Skip to content

MAX326xx: BLE updates, fixed sleep, open-drain LEDs #4398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions features/FEATURE_BLE/targets/TARGET_Maxim/MaximBLE.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -52,35 +52,63 @@
#include "hci_vs.h"

/* Number of WSF buffer pools */
#define WSF_BUF_POOLS 4
#define WSF_BUF_POOLS 5

/*! Free memory for pool buffers. */
static uint8_t mainBufMem[768];
static uint8_t mainBufMem[1040];

/*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{
{ 16, 8 },
{ 32, 4 },
{ 64, 2 },
{ 128, 2 }
{ 128, 2 },
{ 272, 1 }
};

/* Store the Event signalling */
bool isEventsSignaled = false;

/*! WSF handler ID */
wsfHandlerId_t maximHandlerId;
static volatile int reset_complete;

#ifdef BLE_HCI_UART
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work with the internal HCI driver ?
Is it possible to map the driver to other pins ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there are two Maxim HCI drivers; one for SPI and the other UART. These are separate files and do not require the use of ifdef's. Until something changes the HCI driver initialization is the common point within MaximBLE.cpp and thus needs to know what type of mbed objects are needed to reserve peripherals for HCI use.

The HCI drivers use HAL pin mapping to determine the peripheral instance associated with the given SPI slave select or UART transmit pin. With the peripheral instance the other peripheral pins can be determined programmatically. The other pin arguments represent a single pin that can be used without issue. So yes the pins can be mapped to other pins with the same functionality, although this has not been tested.

static DigitalIn _rts(BT_CTS);
static DigitalIn _cts(BT_RTS);
static DigitalIn _clk(BT_CLK);
static DigitalOut _shutdown(BT_RST, 0);
static Serial _uart(BT_TX, BT_RX, 115200);
#else
/* Current mbed SPI API does not support HW slave selects. Configured in HCI driver. */
static DigitalOut _csn(HCI_CSN, 1);
static SPI _spi(HCI_MOSI, HCI_MISO, HCI_SCK, HCI_CSN);
static DigitalOut _rst(HCI_RST, 0);
static InterruptIn _irq(HCI_IRQ);
#endif

/**
* The singleton which represents the MaximBLE transport for the BLE.
*/
static MaximBLE deviceInstance;

extern "C" {

/*
* This function will signal to the user code by calling signalEventsToProcess.
* It is registered and called into the Wsf Stack.
*/
void wsf_mbed_ble_signal_event(void)
{
if (isEventsSignaled == false) {
isEventsSignaled = true;
deviceInstance.signalEventsToProcess(::BLE::DEFAULT_INSTANCE);
}
}

}

/**
* BLE-API requires an implementation of the following function in order to
* obtain its transport handle.
Expand Down Expand Up @@ -240,16 +268,20 @@ ble_error_t MaximBLE::init(BLE::InstanceID_t instanceID, FunctionPointerWithCont
maximHandlerId = WsfOsSetNextHandler(maximHandler);

/* init HCI */
#ifdef BLE_HCI_UART
hciDrvInit(BT_TX, BT_RST, BT_CLK);
#else
_irq.disable_irq();
_irq.rise(hciDrvIsr);
_irq.fall(NULL);
hciDrvInit(HCI_CSN, HCI_RST, HCI_IRQ);
#endif

/* Register for stack callbacks */
DmRegister(DmCback);
DmConnRegister(DM_CLIENT_ID_APP, DmCback);
AttConnRegister(AppServerConnCback);

/* Reset the device */
reset_complete = 0;
DmDevReset();
Expand Down Expand Up @@ -301,12 +333,15 @@ void MaximBLE::waitForEvent(void)

void MaximBLE::processEvents()
{
callDispatcher();
if (isEventsSignaled) {
isEventsSignaled = false;
callDispatcher();
}
}

void MaximBLE::timeoutCallback(void)
{
// do nothing. just an interrupt for wake up.
wsf_mbed_ble_signal_event();
}

void MaximBLE::callDispatcher(void)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified targets/TARGET_Maxim/TARGET_MAX32610/TOOLCHAIN_IAR/libexactLE.a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified targets/TARGET_Maxim/TARGET_MAX32620/TOOLCHAIN_IAR/libexactLE.a
Binary file not shown.
4 changes: 2 additions & 2 deletions targets/TARGET_Maxim/TARGET_MAX32620/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void hal_deepsleep(void)

// Deep Sleep is not working properly on Revisions A3 and earlier
if (part_rev <= REVISION_A3) {
sleep();
hal_sleep();
return;
}

Expand All @@ -128,7 +128,7 @@ void hal_deepsleep(void)
// Do not enter Deep Sleep if connected to VBUS
if (MXC_USB->dev_intfl & MXC_F_USB_DEV_INTFL_VBUS_ST) {
__enable_irq();
sleep();
hal_sleep();
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Copyright (C) 2016-2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -144,6 +144,10 @@ typedef enum {
OWM = P4_0,

// BTLE Module hardwired
BT_TX = P0_0,
BT_RX = P0_1,
BT_RTS = P0_2,
BT_CTS = P0_3,
BT_RST = P1_6,
BT_CLK = P1_7,

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions targets/TARGET_Maxim/TARGET_MAX32630/gpio_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ void gpio_init(gpio_t *obj, PinName name)

void gpio_mode(gpio_t *obj, PinMode mode)
{
#ifdef OPEN_DRAIN_LEDS
if ((obj->name == LED1) || (obj->name == LED2) ||
(obj->name == LED3) || (obj->name == LED4)) {
mode = OpenDrain;
}
#endif

obj->mode = mode;
pin_mode(obj->name, mode);
}
Expand Down
3 changes: 2 additions & 1 deletion targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2060,10 +2060,11 @@
"MAX32630FTHR": {
"inherits": ["Target"],
"core": "Cortex-M4F",
"macros": ["__SYSTEM_HFX=96000000", "TARGET=MAX32630", "TARGET_REV=0x4132"],
"macros": ["__SYSTEM_HFX=96000000", "TARGET=MAX32630", "TARGET_REV=0x4132", "BLE_HCI_UART", "OPEN_DRAIN_LEDS"],
"extra_labels": ["Maxim", "MAX32630"],
"supported_toolchains": ["GCC_ARM", "IAR", "ARM"],
"device_has": ["ANALOGIN", "ERROR_RED", "I2C", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "STDIO_MESSAGES"],
"features": ["BLE"],
"release_versions": ["2", "5"]
},
"EFM32": {
Expand Down