You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0 KiB

  1. #include "ergodox_stm32.h"
  2. #include "i2c_master.h"
  3. extern inline void ergodox_board_led_1_on(void);
  4. extern inline void ergodox_board_led_2_on(void);
  5. extern inline void ergodox_board_led_3_on(void);
  6. extern inline void ergodox_board_led_1_off(void);
  7. extern inline void ergodox_board_led_2_off(void);
  8. extern inline void ergodox_board_led_3_off(void);
  9. extern inline void ergodox_led_all_off(void);
  10. volatile int mcp23017_status = 0x20;
  11. uint8_t i2c_initializied = 0;
  12. void board_init(void) {
  13. AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
  14. }
  15. void bootloader_jump(void) {
  16. // 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.
  17. NVIC_SystemReset();
  18. }
  19. void matrix_init_kb(void)
  20. {
  21. // Init LED Ports
  22. palSetPadMode(GPIOA, 10, PAL_MODE_OUTPUT_PUSHPULL); // LED 1
  23. palSetPadMode(GPIOA, 9, PAL_MODE_OUTPUT_PUSHPULL); // LED 2
  24. palSetPadMode(GPIOA, 8, PAL_MODE_OUTPUT_PUSHPULL); // LED 3
  25. ergodox_blink_all_leds();
  26. matrix_init_user();
  27. }
  28. void ergodox_blink_all_leds(void)
  29. {
  30. ergodox_led_all_off();
  31. // ergodox_led_all_set(LED_BRIGHTNESS_DEFAULT);
  32. ergodox_board_led_1_on();
  33. wait_ms(50);
  34. ergodox_board_led_2_on();
  35. wait_ms(50);
  36. ergodox_board_led_3_on();
  37. wait_ms(50);
  38. ergodox_board_led_1_off();
  39. wait_ms(50);
  40. ergodox_board_led_2_off();
  41. wait_ms(50);
  42. ergodox_board_led_3_off();
  43. }
  44. uint8_t init_mcp23017(void) {
  45. if (!i2c_initializied) {
  46. i2c_init();
  47. i2c_initializied = 1;
  48. }
  49. uint8_t data[2];
  50. data[0] = 0x0;
  51. data[1] = 0b00111111;
  52. mcp23017_status = i2c_writeReg(I2C_ADDR, I2C_IODIRA, data, 2, 50000);
  53. if (mcp23017_status) goto out;
  54. data[0] = 0xFFU;
  55. mcp23017_status = i2c_writeReg(I2C_ADDR, I2C_GPIOA, data, 1, 5000);
  56. if (mcp23017_status) goto out;
  57. mcp23017_status = i2c_writeReg(I2C_ADDR, I2C_GPPUB, data+1, 1, 2);
  58. if (mcp23017_status) goto out;
  59. out:
  60. return mcp23017_status;
  61. // i2c_readReg(I2C_ADDR, );
  62. }