generated from Embedded_Projects/MPyATE_Template
Added LED controls.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
626cfa4521
commit
6d1eca00f2
|
@ -18,6 +18,10 @@ static inline void app_led_off(app_led_t led) {
|
|||
GPIO->B[0][led] = 1U;
|
||||
}
|
||||
|
||||
static inline bool app_led_status(app_led_t led) {
|
||||
return GPIO->B[0][led] ? false : true;
|
||||
}
|
||||
|
||||
static inline void app_led_toggle(app_led_t led) {
|
||||
GPIO->B[0][led] ^= 1U;
|
||||
}
|
||||
|
|
|
@ -1,40 +1,56 @@
|
|||
/* App */
|
||||
#include "app_led.h"
|
||||
#include "app_reg_if.h"
|
||||
|
||||
/* Private */
|
||||
#include "app_sys_utils.h"
|
||||
|
||||
#define APP_SYS_OFFSET_CFG (0x00U)
|
||||
#define APP_SYS_OFFSET_VER (0x0EU)
|
||||
#define APP_SYS_OFFSET_ID (0x0FU)
|
||||
#define APP_SYS_REG_OFFSET_CFG (0x00U)
|
||||
#define APP_SYS_REG_OFFSET_AUX (0x01U)
|
||||
#define APP_SYS_REG_OFFSET_VER (0x0EU)
|
||||
#define APP_SYS_REG_OFFSET_ID (0x0FU)
|
||||
|
||||
#define APP_SYS_CONST_ID (0xEACEU)
|
||||
#define APP_SYS_CONST_VER (0x0000U)
|
||||
|
||||
#define APP_SYS_RST_Pos 15
|
||||
#define APP_SYS_RST_Msk (1U << APP_SYS_RST_Pos)
|
||||
#define APP_SYS_CFG_RST_Pos (15U)
|
||||
#define APP_SYS_CFG_RST_Msk (1U << APP_SYS_CFG_RST_Pos)
|
||||
|
||||
#define APP_SYS_AUX_LED_R_Pos (0U)
|
||||
#define APP_SYS_AUX_LED_R_Msk (1U << APP_SYS_AUX_LED_R_Pos)
|
||||
#define APP_SYS_AUX_LED_G_Pos (1U)
|
||||
#define APP_SYS_AUX_LED_G_Msk (1U << APP_SYS_AUX_LED_G_Pos)
|
||||
#define APP_SYS_AUX_LED_B_Pos (2U)
|
||||
#define APP_SYS_AUX_LED_B_Msk (1U << APP_SYS_AUX_LED_B_Pos)
|
||||
|
||||
static inline uint16_t app_sys_utils_read_reg_cfg(void);
|
||||
static inline uint16_t app_sys_utils_read_reg_aux(void);
|
||||
static inline uint16_t app_sys_utils_read_reg_ver(void);
|
||||
static inline uint16_t app_sys_utils_read_reg_id(void);
|
||||
|
||||
static inline void app_sys_utils_write_reg_cfg(uint16_t data);
|
||||
static inline void app_sys_utils_write_reg_aux(uint16_t data);
|
||||
|
||||
void app_sys_utils_init(void) {
|
||||
/* -- */
|
||||
app_led_off(APP_LED_RED);
|
||||
app_led_off(APP_LED_GREEN);
|
||||
app_led_off(APP_LED_BLUE);
|
||||
}
|
||||
|
||||
uint16_t app_sys_utils_module_reg_read(uint8_t addr) {
|
||||
uint16_t ret = 0x5555;
|
||||
|
||||
switch (addr) {
|
||||
case APP_SYS_OFFSET_CFG:
|
||||
case APP_SYS_REG_OFFSET_CFG:
|
||||
ret = app_sys_utils_read_reg_cfg();
|
||||
break;
|
||||
case APP_SYS_OFFSET_VER:
|
||||
case APP_SYS_REG_OFFSET_AUX:
|
||||
ret = app_sys_utils_read_reg_aux();
|
||||
break;
|
||||
case APP_SYS_REG_OFFSET_VER:
|
||||
ret = app_sys_utils_read_reg_ver();
|
||||
break;
|
||||
case APP_SYS_OFFSET_ID:
|
||||
case APP_SYS_REG_OFFSET_ID:
|
||||
ret = app_sys_utils_read_reg_id();
|
||||
break;
|
||||
default:
|
||||
|
@ -46,9 +62,12 @@ uint16_t app_sys_utils_module_reg_read(uint8_t addr) {
|
|||
|
||||
void app_sys_utils_module_reg_write(uint8_t addr, uint16_t data) {
|
||||
switch (addr) {
|
||||
case APP_SYS_OFFSET_CFG:
|
||||
case APP_SYS_REG_OFFSET_CFG:
|
||||
app_sys_utils_write_reg_cfg(data);
|
||||
break;
|
||||
case APP_SYS_REG_OFFSET_AUX:
|
||||
app_sys_utils_write_reg_aux(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -58,6 +77,24 @@ static inline uint16_t app_sys_utils_read_reg_cfg(void) {
|
|||
return 0x0000U;
|
||||
}
|
||||
|
||||
static inline uint16_t app_sys_utils_read_reg_aux(void) {
|
||||
uint16_t ret = 0x0000U;
|
||||
|
||||
if (app_led_status(APP_LED_RED)) {
|
||||
ret |= APP_SYS_AUX_LED_R_Msk;
|
||||
}
|
||||
|
||||
if (app_led_status(APP_LED_GREEN)) {
|
||||
ret |= APP_SYS_AUX_LED_G_Msk;
|
||||
}
|
||||
|
||||
if (app_led_status(APP_LED_BLUE)) {
|
||||
ret |= APP_SYS_AUX_LED_B_Msk;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint16_t app_sys_utils_read_reg_ver(void) {
|
||||
return APP_SYS_CONST_VER;
|
||||
}
|
||||
|
@ -67,7 +104,27 @@ static inline uint16_t app_sys_utils_read_reg_id(void) {
|
|||
}
|
||||
|
||||
static inline void app_sys_utils_write_reg_cfg(uint16_t data) {
|
||||
if (data & APP_SYS_RST_Msk) {
|
||||
if (data & APP_SYS_CFG_RST_Msk) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void app_sys_utils_write_reg_aux(uint16_t data) {
|
||||
if (data & APP_SYS_AUX_LED_R_Msk) {
|
||||
app_led_on(APP_LED_RED);
|
||||
} else {
|
||||
app_led_off(APP_LED_RED);
|
||||
}
|
||||
|
||||
if (data & APP_SYS_AUX_LED_G_Msk) {
|
||||
app_led_on(APP_LED_GREEN);
|
||||
} else {
|
||||
app_led_off(APP_LED_GREEN);
|
||||
}
|
||||
|
||||
if (data & APP_LED_BLUE) {
|
||||
app_led_on(APP_LED_BLUE);
|
||||
} else {
|
||||
app_led_off(APP_LED_BLUE);
|
||||
}
|
||||
}
|
|
@ -18,7 +18,6 @@ int main(void) {
|
|||
app_i2c_if_init();
|
||||
|
||||
for (;;) {
|
||||
app_led_toggle(APP_LED_RED);
|
||||
SDK_DelayAtLeastUs(500 * 1000, CLOCK_GetCoreSysClkFreq());
|
||||
__WFI();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue