Skip to content

Commit

Permalink
Cascoda SDK patch release v0.23-25
Browse files Browse the repository at this point in the history
reorganize sensorif drivers
add new generic button APIs
add API for disabling jtag interface
increase number of buffers used for the KNX embedded port
fix BSP bug that delays waking up from sleep mode
update documentation
  • Loading branch information
tiniuclx committed Feb 7, 2024
1 parent ad4fbb7 commit 13c0dce
Show file tree
Hide file tree
Showing 72 changed files with 3,289 additions and 1,130 deletions.
1 change: 1 addition & 0 deletions baremetal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(TARGET cascoda-bm-plat)
add_subdirectory(mikrosdk-lib/drv)
add_subdirectory(mikrosdk-click)
add_subdirectory(app/mikrosdk-bm)
add_subdirectory(cascoda-bm-ui)
add_subdirectory(cascoda-bm-devboard)
add_subdirectory(app/pwm-led-dimming)
add_subdirectory(app/buzz2-click-test)
Expand Down
4 changes: 2 additions & 2 deletions baremetal/app/mikrosdk-bm/source/mikrosdk_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void MIKROSDK_Handler_THERMO(void)
++ticker;
handled = 1;

SENSORIF_SPI_Init();
SENSORIF_SPI_Init(false);
temp = thermo_get_temperature(); /* read temperature */
SENSORIF_SPI_Deinit();
printf("Meas %u:\n", ticker);
Expand All @@ -473,7 +473,7 @@ void MIKROSDK_Handler_THERMO(void)
printf("%u.%02u'C", ((temp >> 2) & 0xFFF), (((u32_t)(temp & DECIMAL_MASK_TWO_BITS) * 25)));
printf("\n");

SENSORIF_SPI_Init();
SENSORIF_SPI_Init(false);
temp = thermo_get_junction_temperature(); /* read temperature */
SENSORIF_SPI_Deinit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ u32_t BSP_MicroTimerStop(void);
*/
u32_t BSP_MicroTimerGet(void);

/**
* \brief check if comms interface is connected
* @return true if comms are enabled
*/
bool BSP_IsCommsInterfaceEnabled(void);

#endif // CASCODA_INTERFACE_CORE_H

/**
Expand Down
3 changes: 3 additions & 0 deletions baremetal/cascoda-bm-core/source/cascoda_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void ca_log(ca_loglevel loglevel, const char *format, va_list argp)
if (BSP_IsInsideInterrupt())
return;

if (!BSP_IsCommsInterfaceEnabled())
return;

switch (loglevel)
{
case CA_LOGLEVEL_CRIT:
Expand Down
5 changes: 2 additions & 3 deletions baremetal/cascoda-bm-devboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ project (cascoda-bm-devboard)

add_library(cascoda-bm-devboard
${PROJECT_SOURCE_DIR}/source/devboard_btn.c
${PROJECT_SOURCE_DIR}/source/devboard_btn_ext.c
${PROJECT_SOURCE_DIR}/source/devboard_batt.c
${PROJECT_SOURCE_DIR}/source/devboard_click.c
${PROJECT_SOURCE_DIR}/source/devboard_click_handlers_default.c
Expand All @@ -12,7 +11,7 @@ add_library(cascoda-bm-devboard
)


target_link_libraries(cascoda-bm-devboard PUBLIC cascoda-bm mikrosdk-click)
target_link_libraries(cascoda-bm-devboard PUBLIC cascoda-bm cascoda-btn mikrosdk-click)

target_include_directories(cascoda-bm-devboard PUBLIC ${PROJECT_SOURCE_DIR}/include)

Expand All @@ -31,7 +30,7 @@ add_executable(devboard-click
${PROJECT_SOURCE_DIR}/examples/devboard_app_click.c
)

target_link_libraries(devboard-click cascoda-bm cascoda-bm-devboard mikrosdk-click)
target_link_libraries(devboard-click cascoda-bm cascoda-bm-devboard mikrosdk-click btn-ext-pi4ioe5v96248)
cascoda_make_binary(devboard-click CASCODA_BUILD_BINARIES)
cascoda_put_subdir(devboard devboard-click)

Expand Down
53 changes: 41 additions & 12 deletions baremetal/cascoda-bm-devboard/examples/devboard_app_btn.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@

#define WAKEUP_TIME 10000

#define USE_INTERRUPTS 0 /* power-down and interrupts when 1, polling when 0 */
/* use interrupts when 1, polling only when 0 */
#define USE_INTERRUPTS 1

/* sleep (1) or stay awake (0) */
/* USE_INTERRUPTS also has to be set to (1) for sleeping */
#define USE_SLEEP_MODE 0

/* use shared Button/LED (1) or 'classic' (separate) mode (0) */
#define USE_SHARED_BUTTONS 0

/* jumper position (JUMPER_POS_1 or JUMPER_POS_2) */
#define JUMPER_POS JUMPER_POS_1

#define BLINK_PERIOD_MS 500

Expand Down Expand Up @@ -77,22 +88,35 @@ static void hardware_init(void)
static u8_t nr[3] = {1, 2, 3};

/* Register the SW4 as LED */
DVBD_RegisterLEDOutput(DEV_SWITCH_4, JUMPER_POS_2);
DVBD_RegisterLEDOutput(DEV_SWITCH_4, JUMPER_POS);
DVBD_SetLED(DEV_SWITCH_4, LED_ON);

#if USE_SHARED_BUTTONS
/* Register SW1/SW2/SW3 as Buttons */
#if USE_INTERRUPTS
DVBD_RegisterSharedIRQButtonLED(DEV_SWITCH_1, JUMPER_POS_2);
DVBD_RegisterSharedIRQButtonLED(DEV_SWITCH_2, JUMPER_POS_2);
DVBD_RegisterSharedIRQButtonLED(DEV_SWITCH_3, JUMPER_POS_2);
DVBD_RegisterSharedIRQButtonLED(DEV_SWITCH_1, JUMPER_POS);
DVBD_RegisterSharedIRQButtonLED(DEV_SWITCH_2, JUMPER_POS);
DVBD_RegisterSharedIRQButtonLED(DEV_SWITCH_3, JUMPER_POS);
#else
DVBD_RegisterSharedButtonLED(DEV_SWITCH_1, JUMPER_POS_2);
DVBD_RegisterSharedButtonLED(DEV_SWITCH_2, JUMPER_POS_2);
DVBD_RegisterSharedButtonLED(DEV_SWITCH_3, JUMPER_POS_2);
#endif
DVBD_SetLED(DEV_SWITCH_1, 1);
DVBD_SetLED(DEV_SWITCH_2, 1);
DVBD_SetLED(DEV_SWITCH_3, 0);
DVBD_RegisterSharedButtonLED(DEV_SWITCH_1, JUMPER_POS);
DVBD_RegisterSharedButtonLED(DEV_SWITCH_2, JUMPER_POS);
DVBD_RegisterSharedButtonLED(DEV_SWITCH_3, JUMPER_POS);
#endif // USE_INTERRUPTS
DVBD_SetLED(DEV_SWITCH_1, LED_OFF);
DVBD_SetLED(DEV_SWITCH_2, LED_OFF);
DVBD_SetLED(DEV_SWITCH_3, LED_ON);
#else
#if USE_INTERRUPTS
DVBD_RegisterButtonIRQInput(DEV_SWITCH_1, JUMPER_POS);
DVBD_RegisterButtonIRQInput(DEV_SWITCH_2, JUMPER_POS);
DVBD_RegisterButtonIRQInput(DEV_SWITCH_3, JUMPER_POS);
#else
DVBD_RegisterButtonInput(DEV_SWITCH_1, JUMPER_POS);
DVBD_RegisterButtonInput(DEV_SWITCH_2, JUMPER_POS);
DVBD_RegisterButtonInput(DEV_SWITCH_3, JUMPER_POS);
#endif // USE_INTERRUPTS
#endif // USE_SHARED_BUTTONS

#if DEF_SHORT_CB
DVBD_SetButtonShortPressCallback(DEV_SWITCH_1, &short_press_cb, &nr[0], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonShortPressCallback(DEV_SWITCH_2, &short_press_cb, &nr[1], BTN_SHORTPRESS_RELEASED);
Expand Down Expand Up @@ -131,6 +155,9 @@ bool hardware_can_sleep(void)
if (!USE_INTERRUPTS) /* polling only */
return false;

if (!USE_SLEEP_MODE) /* not sleeping */
return false;

if (!DVBD_CanSleep())
return false;

Expand Down Expand Up @@ -205,12 +232,14 @@ int main(void)

hardware_init();

#if (USE_SHARED_BUTTONS)
struct blink_ctx ctx = {
&blink_tasklet,
DEV_SWITCH_1,
};
TASKLET_Init(&blink_tasklet, &blinkCB);
TASKLET_ScheduleDelta(&blink_tasklet, BLINK_PERIOD_MS, &ctx);
#endif // USE_SHARED_BUTTONS

/* Endless Polling Loop */
while (1)
Expand Down
96 changes: 55 additions & 41 deletions baremetal/cascoda-bm-devboard/examples/devboard_app_click.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
#include "motion_click.h"
#include "relay_click.h"
#include "sht_click.h"
#include "expand13_click.h"
#include "thermo3_click.h"
#include "thermo_click.h"

Expand All @@ -78,7 +77,7 @@
#define CLICK2_TYPE STYPE_NONE

/* sleep (1) or stay awake (0) */
#define USE_SLEEP_MODE 0
#define USE_SLEEP_MODE 1

/* use power control (crowbar) for isolating click boards during power-down (vdd33 off) */
/* note: jumper has to be populated when 1 */
Expand All @@ -92,11 +91,10 @@
#if ((((CLICK1_TYPE == STYPE_THERMO3) || (CLICK2_TYPE == STYPE_THERMO3)) && (THERMO3_USE_INTERRUPT)) || \
(((CLICK1_TYPE == STYPE_SHT) || (CLICK2_TYPE == STYPE_SHT)) && (SHT_USE_INTERRUPT)) || \
(((CLICK1_TYPE == STYPE_MOTION) || (CLICK2_TYPE == STYPE_MOTION)) && (MOTION_USE_INTERRUPT)) || \
(((CLICK1_TYPE == STYPE_FAN) || (CLICK2_TYPE == STYPE_FAN)) && (FAN_USE_INTERRUPT)) || \
(((CLICK1_TYPE == STYPE_EXPAND13) || (CLICK2_TYPE == STYPE_EXPAND13)) && (EXPAND13_USE_INTERRUPT)))
(((CLICK1_TYPE == STYPE_FAN) || (CLICK2_TYPE == STYPE_FAN)) && (FAN_USE_INTERRUPT)))
#define MEASUREMENT_PERIOD DVBD_MAX_SLEEP_TIME
#else
#define MEASUREMENT_PERIOD 1000
#define MEASUREMENT_PERIOD 10000
#endif

/* initialisation functions for all clicks - have to be in correct order */
Expand All @@ -112,7 +110,7 @@ static ca_error (*click_init_function[])(void) = {
CLICK_RELAY_initialise,
CLICK_AMBIENT8_initialise,
CLICK_FAN_initialise,
CLICK_EXPAND13_initialise,
NULL, // EXPAND13 integrated into button handling
};

/* handler functions for all clicks (including acquisition) - have to be in correct order */
Expand Down Expand Up @@ -334,22 +332,18 @@ void hardware_init(void)
else if ((CLICK1_TYPE == STYPE_EXPAND13) || (CLICK2_TYPE == STYPE_EXPAND13))
{
/* register buttons for EXPAND13 */
/* Register SW1/SW2/SW3 as Buttons for comparison */
/* SW1/SW2 registered for comparison */
/* SW3 assumed to be connected to EXPAND13 */
DVBD_RegisterButtonIRQInput(DEV_SWITCH_1, JUMPER_POS_2);
DVBD_RegisterButtonIRQInput(DEV_SWITCH_2, JUMPER_POS_2);
DVBD_RegisterButtonIRQInput(DEV_SWITCH_3, JUMPER_POS_2);
DVBD_SetButtonShortPressCallback(
DEV_SWITCH_1, &btn_short_press_cb, &swnr[DEV_SWITCH_1], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonShortPressCallback(
DEV_SWITCH_2, &btn_short_press_cb, &swnr[DEV_SWITCH_2], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonShortPressCallback(
DEV_SWITCH_3, &btn_short_press_cb, &swnr[DEV_SWITCH_3], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonHoldCallback(DEV_SWITCH_1, &btn_hold_cb, &swnr[DEV_SWITCH_1], BTN_HOLD_TIME_INTERVAL);
DVBD_SetButtonHoldCallback(DEV_SWITCH_2, &btn_hold_cb, &swnr[DEV_SWITCH_2], BTN_HOLD_TIME_INTERVAL);
DVBD_SetButtonHoldCallback(DEV_SWITCH_3, &btn_hold_cb, &swnr[DEV_SWITCH_3], BTN_HOLD_TIME_INTERVAL);
DVBD_SetButtonLongPressCallback(DEV_SWITCH_1, &btn_long_press_cb, &swnr[DEV_SWITCH_1], BTN_LONG_TIME_THRESHOLD);
DVBD_SetButtonLongPressCallback(DEV_SWITCH_2, &btn_long_press_cb, &swnr[DEV_SWITCH_2], BTN_LONG_TIME_THRESHOLD);
DVBD_SetButtonLongPressCallback(DEV_SWITCH_3, &btn_long_press_cb, &swnr[DEV_SWITCH_3], BTN_LONG_TIME_THRESHOLD);
}
else
{
Expand Down Expand Up @@ -391,35 +385,45 @@ void hardware_init(void)

if ((CLICK1_TYPE == STYPE_EXPAND13) || (CLICK2_TYPE == STYPE_EXPAND13))
{
/* Register extended switches as buttons */
DVBD_RegisterButtonInputExt(DEV_SWITCH_EXT_1);
DVBD_RegisterButtonInputExt(DEV_SWITCH_EXT_2);
DVBD_RegisterButtonInputExt(DEV_SWITCH_EXT_3);
DVBD_RegisterButtonInputExt(DEV_SWITCH_EXT_4);
DVBD_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_1, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_1 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_2, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_2 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_3, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_3 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_4, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_4 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
DVBD_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_1, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_1 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
DVBD_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_2, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_2 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
DVBD_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_3, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_3 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
DVBD_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_4, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_4 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
DVBD_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_1, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_1 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
DVBD_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_2, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_2 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
DVBD_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_3, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_3 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
DVBD_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_4, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_4 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
/* initialise gpio extender (expand13) */
if (SIF_InitialiseGPIOExt())
{
printf("GPIO Extender Initialisation failed\n");
set_hw_error();
}
else
{
printf("GPIO Extender Initialised\n");
/* Register extended switches as buttons */
SIF_RegisterButtonInputExt(DEV_SWITCH_EXT_1);
SIF_RegisterButtonInputExt(DEV_SWITCH_EXT_2);
SIF_RegisterButtonInputExt(DEV_SWITCH_EXT_3);
SIF_RegisterButtonInputExt(DEV_SWITCH_EXT_4);
SIF_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_1, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_1 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
SIF_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_2, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_2 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
SIF_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_3, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_3 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
SIF_SetButtonShortPressCallbackExt(
DEV_SWITCH_EXT_4, &btn_short_press_cb, &swnr[DEV_SWITCH_EXT_4 + NUM_LEDBTN], BTN_SHORTPRESS_RELEASED);
SIF_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_1, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_1 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
SIF_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_2, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_2 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
SIF_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_3, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_3 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
SIF_SetButtonHoldCallbackExt(
DEV_SWITCH_EXT_4, &btn_hold_cb, &swnr[DEV_SWITCH_EXT_4 + NUM_LEDBTN], BTN_HOLD_TIME_INTERVAL);
SIF_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_1, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_1 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
SIF_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_2, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_2 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
SIF_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_3, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_3 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
SIF_SetButtonLongPressCallbackExt(
DEV_SWITCH_EXT_4, &btn_long_press_cb, &swnr[DEV_SWITCH_EXT_4 + NUM_LEDBTN], BTN_LONG_TIME_THRESHOLD);
}
}

/* init scheduling, and trigger first calls (after 100 ms) to initialise click sensor interface in handlers */
Expand All @@ -432,6 +436,10 @@ void hardware_poll(void)
{
/* check buttons */
DVBD_PollButtons();
if ((CLICK1_TYPE == STYPE_EXPAND13) || (CLICK2_TYPE == STYPE_EXPAND13))
{
SIF_PollButtonsExt();
}

/* click sensor handlers */
check_alarms();
Expand Down Expand Up @@ -468,6 +476,12 @@ bool hardware_can_sleep(void)
if (!DVBD_CanSleep())
return false;

if ((CLICK1_TYPE == STYPE_EXPAND13) || (CLICK2_TYPE == STYPE_EXPAND13))
{
if (!SIF_CanSleepExt())
return false;
}

if (g_hw_error)
return false;

Expand Down
Loading

0 comments on commit 13c0dce

Please sign in to comment.