#include "elite_dev.h" #include "nrf_gpio.h" #include "nrf_log.h" #if (DEF_ELITE_MODEL == DEF_ELITE_DEV) #define VERSION_DATE_YEAR 24 #define VERSION_DATE_MONTH 7 #define VERSION_DATE_DAY 2 #define VERSION_DATE_HOUR 11 #define VERSION_DATE_MINUTE 32 static void cis_version(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); uint8_t cis_ver[] = { CIS_VERSION, VERSION_DATE_YEAR, VERSION_DATE_MONTH, VERSION_DATE_DAY, VERSION_DATE_HOUR, VERSION_DATE_MINUTE, }; extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); le_data_upadate((void *)cis_ver, sizeof(cis_ver)); } static void vis_rst(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); } #define UNDEF_GPIO 0xFFFFFFFF // The GPIO corresponding to the pin const uint32_t pin_to_gpio_table[] = { [6] = NRF_GPIO_PIN_MAP(0, 22), [8] = NRF_GPIO_PIN_MAP(0, 25), [9] = NRF_GPIO_PIN_MAP(0, 19), [10] = NRF_GPIO_PIN_MAP(0, 21), [11] = NRF_GPIO_PIN_MAP(1, 00), [12] = NRF_GPIO_PIN_MAP(0, 18), [13] = NRF_GPIO_PIN_MAP(0, 17), [14] = NRF_GPIO_PIN_MAP(0, 20), [16] = NRF_GPIO_PIN_MAP(0, 14), [17] = NRF_GPIO_PIN_MAP(0, 13), [18] = NRF_GPIO_PIN_MAP(0, 11), [20] = NRF_GPIO_PIN_MAP(0, 15), [25] = NRF_GPIO_PIN_MAP(1, 8), [26] = NRF_GPIO_PIN_MAP(0, 12), [27] = NRF_GPIO_PIN_MAP(0, 7), [28] = NRF_GPIO_PIN_MAP(1, 9), [29] = NRF_GPIO_PIN_MAP(0, 8), [30] = NRF_GPIO_PIN_MAP(0, 6), [31] = NRF_GPIO_PIN_MAP(0, 5), [32] = NRF_GPIO_PIN_MAP(0, 27), [33] = NRF_GPIO_PIN_MAP(0, 26), [34] = NRF_GPIO_PIN_MAP(0, 4), [36] = NRF_GPIO_PIN_MAP(0, 1), [37] = NRF_GPIO_PIN_MAP(0, 29), [38] = NRF_GPIO_PIN_MAP(0, 0), [39] = NRF_GPIO_PIN_MAP(0, 31), [40] = NRF_GPIO_PIN_MAP(1, 15), [41] = NRF_GPIO_PIN_MAP(0, 2), [42] = NRF_GPIO_PIN_MAP(0, 30), [43] = NRF_GPIO_PIN_MAP(0, 28), [44] = NRF_GPIO_PIN_MAP(1, 12), [45] = NRF_GPIO_PIN_MAP(1, 14), [46] = NRF_GPIO_PIN_MAP(0, 3), [47] = NRF_GPIO_PIN_MAP(1, 13), [48] = NRF_GPIO_PIN_MAP(1, 3), [49] = NRF_GPIO_PIN_MAP(1, 10), [50] = NRF_GPIO_PIN_MAP(1, 6), [51] = NRF_GPIO_PIN_MAP(1, 11), [52] = NRF_GPIO_PIN_MAP(0, 10), [53] = NRF_GPIO_PIN_MAP(0, 9), [59] = NRF_GPIO_PIN_MAP(1, 2), [60] = NRF_GPIO_PIN_MAP(0, 24), [61] = NRF_GPIO_PIN_MAP(0, 23), [62] = NRF_GPIO_PIN_MAP(0, 16), }; static uint32_t bmd380pins_convert_to_gpio(uint32_t pin) { uint32_t gpio; switch (pin) { case 6: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 16: case 17: case 18: case 20: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 33: case 34: case 36: case 37: case 38: case 39: case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 48: case 49: case 50: case 51: case 52: case 53: case 59: case 60: case 61: case 62: gpio = pin_to_gpio_table[pin]; break; default: gpio = UNDEF_GPIO; NRF_LOG_INFO("UNDEF_GPIO: pin %d can't convert to gpio number", pin); break; } return gpio; } static void set_bmd380_pin_signal(uint32_t pin, uint32_t high_low) { uint32_t gpio = bmd380pins_convert_to_gpio(pin); if (gpio != UNDEF_GPIO) { nrf_gpio_cfg_output(gpio); nrf_gpio_pin_write(gpio, high_low); NRF_LOG_INFO("set pin %d (gpio %d) = %d", pin, gpio, high_low); } } /* dev_mode_gpio_function (1)0x3000FFA000ppss -func: set_bmd380_pin_signal -pp: pin number 06h-3Fh 06h: P0.22_GPIO 08h: P0.25_GPIO ...... 3Eh: P0.16_GPIO -ss: signal 00h-01h 00h: low 01h: high (2)0x3000FFA001ss -func: set_bmd380 all pin signal high/low -ss: signal 00h-01h 00h: low 01h: high */ void dev_mode_gpio_function(uint8_t *ins) { struct __PACKED { uint8_t id : 4; uint8_t : 4; uint16_t magic : 16; uint8_t dev_opcode; uint8_t gpio_function_opcode; uint8_t param[]; } *p_ins = (void *)ins; switch (p_ins->gpio_function_opcode) { case 0x00: { uint32_t pin = p_ins->param[0]; uint32_t high_low = p_ins->param[1]; set_bmd380_pin_signal(pin, high_low); break; } case 0x01: { uint32_t high_low = p_ins->param[0]; uint32_t set_pin[44] = {6, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 20, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 59, 60, 61, 62}; for (int i=0; imagic != MAGIC_NUM) { return; } // TODO... switch (p_ins->opcode) { case 0xA0: dev_mode_gpio_function(ins); break; default: break; } } const elite_instance_t pel_elite_instance = { .cis_func = { [CIS_VERSION] = cis_version, }, .vis_func = { [VIS_RST] = vis_rst, }, .ris_func = { [DEV_MODE] = dev_mode, } }; const elite_instance_t *dev_init(void) { return &pel_elite_instance; } #endif /* !DEF_ELITE_MODEL */