ergodox_stm32.c (2048B)
1 #include "ergodox_stm32.h" 2 #include "i2c_master.h" 3 4 extern inline void ergodox_board_led_1_on(void); 5 extern inline void ergodox_board_led_2_on(void); 6 extern inline void ergodox_board_led_3_on(void); 7 extern inline void ergodox_board_led_1_off(void); 8 extern inline void ergodox_board_led_2_off(void); 9 extern inline void ergodox_board_led_3_off(void); 10 extern inline void ergodox_led_all_off(void); 11 12 volatile int mcp23017_status = 0x20; 13 uint8_t i2c_initializied = 0; 14 15 void board_init(void) { 16 AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE; 17 } 18 19 void bootloader_jump(void) { 20 // This board doesn't use the "standard" stm32duino bootloader, and is resident in memory at the base location. All we can do here is reset. 21 NVIC_SystemReset(); 22 } 23 24 void matrix_init_kb(void) 25 { 26 // Init LED Ports 27 palSetPadMode(GPIOA, 10, PAL_MODE_OUTPUT_PUSHPULL); // LED 1 28 palSetPadMode(GPIOA, 9, PAL_MODE_OUTPUT_PUSHPULL); // LED 2 29 palSetPadMode(GPIOA, 8, PAL_MODE_OUTPUT_PUSHPULL); // LED 3 30 31 ergodox_blink_all_leds(); 32 33 matrix_init_user(); 34 } 35 36 void ergodox_blink_all_leds(void) 37 { 38 ergodox_led_all_off(); 39 // ergodox_led_all_set(LED_BRIGHTNESS_DEFAULT); 40 ergodox_board_led_1_on(); 41 wait_ms(50); 42 ergodox_board_led_2_on(); 43 wait_ms(50); 44 ergodox_board_led_3_on(); 45 wait_ms(50); 46 ergodox_board_led_1_off(); 47 wait_ms(50); 48 ergodox_board_led_2_off(); 49 wait_ms(50); 50 ergodox_board_led_3_off(); 51 } 52 53 uint8_t init_mcp23017(void) { 54 if (!i2c_initializied) { 55 i2c_init(); 56 i2c_initializied = 1; 57 } 58 59 uint8_t data[2]; 60 data[0] = 0x0; 61 data[1] = 0b00111111; 62 mcp23017_status = i2c_write_register(I2C_ADDR, I2C_IODIRA, data, 2, 50000); 63 if (mcp23017_status) goto out; 64 data[0] = 0xFFU; 65 mcp23017_status = i2c_write_register(I2C_ADDR, I2C_GPIOA, data, 1, 5000); 66 if (mcp23017_status) goto out; 67 mcp23017_status = i2c_write_register(I2C_ADDR, I2C_GPPUB, data+1, 1, 2); 68 if (mcp23017_status) goto out; 69 70 out: 71 return mcp23017_status; 72 // i2c_read_register(I2C_ADDR, ); 73 } 74