From 690a08cbbbf41300214d9b74daffbbccefab4a87 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 15 Jan 2018 16:06:49 -0500 Subject: [PATCH 01/42] fix up arm audio implementation --- quantum/audio/audio_arm.c | 223 ++++++++++++++++++++++++++++++-------- 1 file changed, 178 insertions(+), 45 deletions(-) diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index 43c8d67c48..6f8b5e3078 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -77,23 +77,48 @@ bool glissando = true; #endif float startup_song[][2] = STARTUP_SONG; -static void gpt_cb6(GPTDriver *gptp); -static void gpt_cb7(GPTDriver *gptp); static void gpt_cb8(GPTDriver *gptp); +#define DAC_BUFFER_SIZE 360 + +#define START_CHANNEL_1() gptStart(&GPTD6, &gpt6cfg1); \ + gptStartContinuous(&GPTD6, 2U) +#define START_CHANNEL_2() gptStart(&GPTD7, &gpt7cfg1); \ + gptStartContinuous(&GPTD7, 2U) +#define STOP_CHANNEL_1() gptStopTimer(&GPTD6) +#define STOP_CHANNEL_2() gptStopTimer(&GPTD7) +#define RESTART_CHANNEL_1() STOP_CHANNEL_1(); \ + START_CHANNEL_1() +#define RESTART_CHANNEL_2() STOP_CHANNEL_1(); \ + START_CHANNEL_1() +#define UPDATE_CHANNEL_1_FREQ(freq) gpt6cfg1.frequency = freq * DAC_BUFFER_SIZE; \ + RESTART_CHANNEL_1() +#define UPDATE_CHANNEL_2_FREQ(freq) gpt7cfg1.frequency = freq * DAC_BUFFER_SIZE; \ + RESTART_CHANNEL_2() +#define GET_CHANNEL_1_FREQ gpt6cfg1.frequency +#define GET_CHANNEL_2_FREQ gpt7cfg1.frequency + + /* * GPT6 configuration. */ +// static const GPTConfig gpt6cfg1 = { +// .frequency = 1000000U, +// .callback = NULL, +// .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */ +// .dier = 0U +// }; + GPTConfig gpt6cfg1 = { - .frequency = 440, - .callback = gpt_cb6, + .frequency = 440U*DAC_BUFFER_SIZE, + .callback = NULL, .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */ .dier = 0U }; GPTConfig gpt7cfg1 = { - .frequency = 440, - .callback = gpt_cb7, + .frequency = 440U*DAC_BUFFER_SIZE, + .callback = NULL, .cr2 = TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */ .dier = 0U }; @@ -105,15 +130,122 @@ GPTConfig gpt8cfg1 = { .dier = 0U }; -static void gpt_cb6(GPTDriver *gptp) { - palTogglePad(GPIOA, 4); + +/* + * DAC test buffer (sine wave). + */ +// static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { +// 2047, 2082, 2118, 2154, 2189, 2225, 2260, 2296, 2331, 2367, 2402, 2437, +// 2472, 2507, 2542, 2576, 2611, 2645, 2679, 2713, 2747, 2780, 2813, 2846, +// 2879, 2912, 2944, 2976, 3008, 3039, 3070, 3101, 3131, 3161, 3191, 3221, +// 3250, 3278, 3307, 3335, 3362, 3389, 3416, 3443, 3468, 3494, 3519, 3544, +// 3568, 3591, 3615, 3637, 3660, 3681, 3703, 3723, 3744, 3763, 3782, 3801, +// 3819, 3837, 3854, 3870, 3886, 3902, 3917, 3931, 3944, 3958, 3970, 3982, +// 3993, 4004, 4014, 4024, 4033, 4041, 4049, 4056, 4062, 4068, 4074, 4078, +// 4082, 4086, 4089, 4091, 4092, 4093, 4094, 4093, 4092, 4091, 4089, 4086, +// 4082, 4078, 4074, 4068, 4062, 4056, 4049, 4041, 4033, 4024, 4014, 4004, +// 3993, 3982, 3970, 3958, 3944, 3931, 3917, 3902, 3886, 3870, 3854, 3837, +// 3819, 3801, 3782, 3763, 3744, 3723, 3703, 3681, 3660, 3637, 3615, 3591, +// 3568, 3544, 3519, 3494, 3468, 3443, 3416, 3389, 3362, 3335, 3307, 3278, +// 3250, 3221, 3191, 3161, 3131, 3101, 3070, 3039, 3008, 2976, 2944, 2912, +// 2879, 2846, 2813, 2780, 2747, 2713, 2679, 2645, 2611, 2576, 2542, 2507, +// 2472, 2437, 2402, 2367, 2331, 2296, 2260, 2225, 2189, 2154, 2118, 2082, +// 2047, 2012, 1976, 1940, 1905, 1869, 1834, 1798, 1763, 1727, 1692, 1657, +// 1622, 1587, 1552, 1518, 1483, 1449, 1415, 1381, 1347, 1314, 1281, 1248, +// 1215, 1182, 1150, 1118, 1086, 1055, 1024, 993, 963, 933, 903, 873, +// 844, 816, 787, 759, 732, 705, 678, 651, 626, 600, 575, 550, +// 526, 503, 479, 457, 434, 413, 391, 371, 350, 331, 312, 293, +// 275, 257, 240, 224, 208, 192, 177, 163, 150, 136, 124, 112, +// 101, 90, 80, 70, 61, 53, 45, 38, 32, 26, 20, 16, +// 12, 8, 5, 3, 2, 1, 0, 1, 2, 3, 5, 8, +// 12, 16, 20, 26, 32, 38, 45, 53, 61, 70, 80, 90, +// 101, 112, 124, 136, 150, 163, 177, 192, 208, 224, 240, 257, +// 275, 293, 312, 331, 350, 371, 391, 413, 434, 457, 479, 503, +// 526, 550, 575, 600, 626, 651, 678, 705, 732, 759, 787, 816, +// 844, 873, 903, 933, 963, 993, 1024, 1055, 1086, 1118, 1150, 1182, +// 1215, 1248, 1281, 1314, 1347, 1381, 1415, 1449, 1483, 1518, 1552, 1587, +// 1622, 1657, 1692, 1727, 1763, 1798, 1834, 1869, 1905, 1940, 1976, 2012 +// }; + +// squarewave +static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* + * DAC streaming callback. + */ +size_t nx = 0, ny = 0, nz = 0; +static void end_cb1(DACDriver *dacp, const dacsample_t *buffer, size_t n) { + + (void)dacp; + + nz++; + if (dac_buffer == buffer) { + nx += n; + } + else { + ny += n; + } + + if ((nz % 1000) == 0) { + // palTogglePad(GPIOD, GPIOD_LED3); + } } +/* + * DAC error callback. + */ +static void error_cb1(DACDriver *dacp, dacerror_t err) { -static void gpt_cb7(GPTDriver *gptp) { - palTogglePad(GPIOA, 5); + (void)dacp; + (void)err; + + chSysHalt("DAC failure"); } +static const DACConfig dac1cfg1 = { + .init = 2047U, + .datamode = DAC_DHRM_12BIT_RIGHT +}; + +static const DACConversionGroup dacgrpcfg1 = { + .num_channels = 1U, + .end_cb = end_cb1, + .error_cb = error_cb1, + .trigger = DAC_TRG(0) +}; + void audio_init() { @@ -128,8 +260,27 @@ void audio_init() // audio_config.raw = eeconfig_read_audio(); audio_config.enable = true; - palSetPadMode(GPIOA, 4, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL); + /* + * Starting DAC1 driver, setting up the output pin as analog as suggested + * by the Reference Manual. + */ + palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); + palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); + dacStart(&DACD1, &dac1cfg1); + + /* + * Starting GPT6 driver, it is used for triggering the DAC. + */ + START_CHANNEL_1(); + START_CHANNEL_2(); + + /* + * Starting a continuous conversion. + */ + dacStartConversion(&DACD1, &dacgrpcfg1, + (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE); + // gptStartContinuous(&GPTD6, 2U); + audio_initialized = true; @@ -193,8 +344,8 @@ void stop_note(float freq) voice_place = 0; } if (voices == 0) { - gptStopTimer(&GPTD6); - gptStopTimer(&GPTD7); + STOP_CHANNEL_1(); + STOP_CHANNEL_2(); gptStopTimer(&GPTD8); frequency = 0; frequency_alt = 0; @@ -224,20 +375,6 @@ float vibrato(float average_freq) { #endif -static void restart_gpt6(void) { - // gptStopTimer(&GPTD6); - - gptStart(&GPTD6, &gpt6cfg1); - gptStartContinuous(&GPTD6, 2U); -} - -static void restart_gpt7(void) { - // gptStopTimer(&GPTD7); - - gptStart(&GPTD7, &gpt7cfg1); - gptStartContinuous(&GPTD7, 2U); -} - static void gpt_cb8(GPTDriver *gptp) { float freq; @@ -280,13 +417,12 @@ static void gpt_cb8(GPTDriver *gptp) { freq_alt = 30.52; } - if (gpt6cfg1.frequency != (uint16_t)freq_alt) { - gpt6cfg1.frequency = freq_alt; - restart_gpt6(); + if (GET_CHANNEL_1_FREQ != (uint16_t)freq_alt) { + UPDATE_CHANNEL_1_FREQ(freq_alt); } //note_timbre; } else { - // gptStopTimer(&GPTD6); + STOP_CHANNEL_1(); } if (polyphony_rate > 0) { @@ -342,9 +478,8 @@ static void gpt_cb8(GPTDriver *gptp) { } - if (gpt7cfg1.frequency != (uint16_t)freq) { - gpt7cfg1.frequency = freq; - restart_gpt7(); + if (GET_CHANNEL_2_FREQ != (uint16_t)freq) { + UPDATE_CHANNEL_2_FREQ(freq); } //note_timbre; } else { @@ -370,11 +505,9 @@ static void gpt_cb8(GPTDriver *gptp) { freq = voice_envelope(freq); - if (gpt6cfg1.frequency != (uint16_t)freq) { - gpt6cfg1.frequency = freq; - restart_gpt6(); - gpt7cfg1.frequency = freq; - restart_gpt7(); + if (GET_CHANNEL_1_FREQ != (uint16_t)freq) { + UPDATE_CHANNEL_1_FREQ(freq); + UPDATE_CHANNEL_2_FREQ(freq); } //note_timbre; } else { @@ -384,7 +517,7 @@ static void gpt_cb8(GPTDriver *gptp) { note_position++; bool end_of_note = false; - if (gpt6cfg1.frequency > 0) { + if (GET_CHANNEL_1_FREQ > 0) { if (!note_resting) end_of_note = (note_position >= (note_length*16 - 1)); else @@ -399,8 +532,8 @@ static void gpt_cb8(GPTDriver *gptp) { if (notes_repeat) { current_note = 0; } else { - gptStopTimer(&GPTD6); - gptStopTimer(&GPTD7); + STOP_CHANNEL_1(); + STOP_CHANNEL_2(); // gptStopTimer(&GPTD8); playing_notes = false; return; @@ -492,8 +625,8 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat) gptStart(&GPTD8, &gpt8cfg1); gptStartContinuous(&GPTD8, 2U); - restart_gpt6(); - restart_gpt7(); + RESTART_CHANNEL_1(); + RESTART_CHANNEL_2(); } } From 31df12c84fc5bf2e938394b026d9027aa881e71b Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 26 Jan 2018 23:56:48 -0500 Subject: [PATCH 02/42] chibios stack size inc --- tmk_core/chibios.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk index cb0482d757..bc3097f4b2 100644 --- a/tmk_core/chibios.mk +++ b/tmk_core/chibios.mk @@ -6,7 +6,7 @@ # Stack size to be allocated to the Cortex-M process stack. This stack is # the stack used by the main() thread. ifeq ($(USE_PROCESS_STACKSIZE),) - USE_PROCESS_STACKSIZE = 0x200 + USE_PROCESS_STACKSIZE = 0x800 endif # Stack size to the allocated to the Cortex-M main/exceptions stack. This From 2165f9d654a3c44fc51f2e6638807f1be21ff9da Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 27 Jan 2018 02:05:09 -0500 Subject: [PATCH 03/42] get one channel working --- quantum/audio/audio_arm.c | 69 ++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index 6f8b5e3078..f5ca417ba5 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -89,8 +89,8 @@ static void gpt_cb8(GPTDriver *gptp); #define STOP_CHANNEL_2() gptStopTimer(&GPTD7) #define RESTART_CHANNEL_1() STOP_CHANNEL_1(); \ START_CHANNEL_1() -#define RESTART_CHANNEL_2() STOP_CHANNEL_1(); \ - START_CHANNEL_1() +#define RESTART_CHANNEL_2() STOP_CHANNEL_2(); \ + START_CHANNEL_2() #define UPDATE_CHANNEL_1_FREQ(freq) gpt6cfg1.frequency = freq * DAC_BUFFER_SIZE; \ RESTART_CHANNEL_1() #define UPDATE_CHANNEL_2_FREQ(freq) gpt7cfg1.frequency = freq * DAC_BUFFER_SIZE; \ @@ -202,6 +202,41 @@ static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +// squarewave +static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = { + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + /* * DAC streaming callback. */ @@ -246,6 +281,18 @@ static const DACConversionGroup dacgrpcfg1 = { .trigger = DAC_TRG(0) }; +static const DACConfig dac1cfg2 = { + .init = 2047U, + .datamode = DAC_DHRM_12BIT_RIGHT +}; + +static const DACConversionGroup dacgrpcfg2 = { + .num_channels = 1U, + .end_cb = end_cb1, + .error_cb = error_cb1, + .trigger = DAC_TRG(0) +}; + void audio_init() { @@ -267,6 +314,7 @@ void audio_init() palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); dacStart(&DACD1, &dac1cfg1); + dacStart(&DACD2, &dac1cfg2); /* * Starting GPT6 driver, it is used for triggering the DAC. @@ -279,6 +327,8 @@ void audio_init() */ dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE); + dacStartConversion(&DACD2, &dacgrpcfg2, + (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE); // gptStartContinuous(&GPTD6, 2U); @@ -417,12 +467,10 @@ static void gpt_cb8(GPTDriver *gptp) { freq_alt = 30.52; } - if (GET_CHANNEL_1_FREQ != (uint16_t)freq_alt) { - UPDATE_CHANNEL_1_FREQ(freq_alt); + if (GET_CHANNEL_2_FREQ != (uint16_t)freq_alt) { + UPDATE_CHANNEL_2_FREQ(freq_alt); } //note_timbre; - } else { - STOP_CHANNEL_1(); } if (polyphony_rate > 0) { @@ -478,12 +526,10 @@ static void gpt_cb8(GPTDriver *gptp) { } - if (GET_CHANNEL_2_FREQ != (uint16_t)freq) { - UPDATE_CHANNEL_2_FREQ(freq); + if (GET_CHANNEL_1_FREQ != (uint16_t)freq) { + UPDATE_CHANNEL_1_FREQ(freq); } //note_timbre; - } else { - // gptStopTimer(&GPTD7); } } @@ -592,7 +638,8 @@ void play_note(float freq, int vol) { gptStart(&GPTD8, &gpt8cfg1); gptStartContinuous(&GPTD8, 2U); - + RESTART_CHANNEL_1(); + RESTART_CHANNEL_2(); } } From 78ea99d154eab6afb26389cb279728094fb0a7d9 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 31 Jan 2018 13:31:20 -0500 Subject: [PATCH 04/42] start f303 handwire --- keyboards/_qmk_handwire/_qmk_handwire.c | 25 + keyboards/_qmk_handwire/_qmk_handwire.h | 45 + .../boards/GENERIC_STM32_F303XC/board.c | 124 ++ .../boards/GENERIC_STM32_F303XC/board.h | 1187 +++++++++++++++++ .../boards/GENERIC_STM32_F303XC/board.mk | 5 + keyboards/_qmk_handwire/bootloader_defs.h | 7 + keyboards/_qmk_handwire/chconf.h | 520 ++++++++ keyboards/_qmk_handwire/config.h | 133 ++ keyboards/_qmk_handwire/halconf.h | 388 ++++++ .../_qmk_handwire/keymaps/default/keymap.c | 127 ++ .../_qmk_handwire/keymaps/default/readme.md | 1 + keyboards/_qmk_handwire/led.c | 53 + keyboards/_qmk_handwire/matrix.c | 175 +++ keyboards/_qmk_handwire/mcuconf.h | 257 ++++ keyboards/_qmk_handwire/readme.md | 14 + keyboards/_qmk_handwire/rules.mk | 55 + 16 files changed, 3116 insertions(+) create mode 100644 keyboards/_qmk_handwire/_qmk_handwire.c create mode 100644 keyboards/_qmk_handwire/_qmk_handwire.h create mode 100644 keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c create mode 100644 keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h create mode 100644 keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.mk create mode 100644 keyboards/_qmk_handwire/bootloader_defs.h create mode 100644 keyboards/_qmk_handwire/chconf.h create mode 100644 keyboards/_qmk_handwire/config.h create mode 100644 keyboards/_qmk_handwire/halconf.h create mode 100644 keyboards/_qmk_handwire/keymaps/default/keymap.c create mode 100644 keyboards/_qmk_handwire/keymaps/default/readme.md create mode 100644 keyboards/_qmk_handwire/led.c create mode 100644 keyboards/_qmk_handwire/matrix.c create mode 100644 keyboards/_qmk_handwire/mcuconf.h create mode 100644 keyboards/_qmk_handwire/readme.md create mode 100644 keyboards/_qmk_handwire/rules.mk diff --git a/keyboards/_qmk_handwire/_qmk_handwire.c b/keyboards/_qmk_handwire/_qmk_handwire.c new file mode 100644 index 0000000000..a7f460b1a9 --- /dev/null +++ b/keyboards/_qmk_handwire/_qmk_handwire.c @@ -0,0 +1,25 @@ +/* Copyright 2017 skully + * 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "_qmk_handwire.h" + +void matrix_init_kb(void) { + +} + +void matrix_scan_kb(void) { + +} diff --git a/keyboards/_qmk_handwire/_qmk_handwire.h b/keyboards/_qmk_handwire/_qmk_handwire.h new file mode 100644 index 0000000000..886b92016a --- /dev/null +++ b/keyboards/_qmk_handwire/_qmk_handwire.h @@ -0,0 +1,45 @@ +/* Copyright 2017 skully + * 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef QMK_HANDWIRE_H +#define QMK_HANDWIRE_H + +#include "quantum.h" + +/* + * These are shortcuts to help you work with the various layout options. If your + * keymap works with one of the LAYOUT_...() macros you are encouraged to use that + * and to contribute your keymap to the corresponding layout in + * `qmk_firmware/layouts/community`. + */ + +/* The fully-featured KEYMAP() that has every single key available in the matrix. + */ +#define KEYMAP(\ + k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, k0c, k0d, k0e, \ + k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1e, \ + k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2e, \ + k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3e, \ + k40, k41, k42, k47, k4a, k4b, k4c, k4e \ +) { \ + { k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, k0c, k0d, k0e, }, \ + { k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, KC_NO, k1e, }, \ + { k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, KC_NO, k2e, }, \ + { k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, KC_NO, k3e, }, \ + { k40, k41, k42, KC_NO, KC_NO, KC_NO, KC_NO, k47, KC_NO, KC_NO, k4a, k4b, k4c, KC_NO, k4e, }, \ +} + +#endif \ No newline at end of file diff --git a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c new file mode 100644 index 0000000000..897f20a887 --- /dev/null +++ b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c @@ -0,0 +1,124 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "hal.h" + +#if HAL_USE_PAL || defined(__DOXYGEN__) +/** + * @brief PAL setup. + * @details Digital I/O ports static configuration as defined in @p board.h. + * This variable is used by the HAL when initializing the PAL driver. + */ +const PALConfig pal_default_config = { +#if STM32_HAS_GPIOA + {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, + VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH}, +#endif +#if STM32_HAS_GPIOB + {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, + VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH}, +#endif +#if STM32_HAS_GPIOC + {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, + VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH}, +#endif +#if STM32_HAS_GPIOD + {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, + VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH}, +#endif +#if STM32_HAS_GPIOE + {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR, + VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH}, +#endif +#if STM32_HAS_GPIOF + {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR, + VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH}, +#endif +#if STM32_HAS_GPIOG + {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR, + VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH}, +#endif +#if STM32_HAS_GPIOH + {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR, + VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH}, +#endif +#if STM32_HAS_GPIOI + {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR, + VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH} +#endif +}; +#endif + +/** + * @brief Early initialization code. + * @details This initialization must be performed just after stack setup + * and before any other initialization. + */ +void __early_init(void) { + + stm32_clock_init(); +} + +#if HAL_USE_SDC || defined(__DOXYGEN__) +/** + * @brief SDC card detection. + */ +bool sdc_lld_is_card_inserted(SDCDriver *sdcp) { + + (void)sdcp; + /* TODO: Fill the implementation.*/ + return true; +} + +/** + * @brief SDC card write protection detection. + */ +bool sdc_lld_is_write_protected(SDCDriver *sdcp) { + + (void)sdcp; + /* TODO: Fill the implementation.*/ + return false; +} +#endif /* HAL_USE_SDC */ + +#if HAL_USE_MMC_SPI || defined(__DOXYGEN__) +/** + * @brief MMC_SPI card detection. + */ +bool mmc_lld_is_card_inserted(MMCDriver *mmcp) { + + (void)mmcp; + /* TODO: Fill the implementation.*/ + return true; +} + +/** + * @brief MMC_SPI card write protection detection. + */ +bool mmc_lld_is_write_protected(MMCDriver *mmcp) { + + (void)mmcp; + /* TODO: Fill the implementation.*/ + return false; +} +#endif + +/** + * @brief Board-specific initialization code. + * @todo Add your board-specific code, if any. + */ +void boardInit(void) { +} diff --git a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h new file mode 100644 index 0000000000..7405c0ea90 --- /dev/null +++ b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h @@ -0,0 +1,1187 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef _BOARD_H_ +#define _BOARD_H_ + +/* + * Setup for Clueboard 60% Keyboard + */ + +/* + * Board identifier. + */ +#define BOARD_GENERIC_STM32_F303XC +#define BOARD_NAME "Clueboard 60 PCB" + +/* + * Board oscillators-related settings. + * NOTE: LSE not fitted. + */ +#if !defined(STM32_LSECLK) +#define STM32_LSECLK 0U +#endif + +#define STM32_LSEDRV (3U << 3U) + +#if !defined(STM32_HSECLK) +#define STM32_HSECLK 8000000U +#endif + +// #define STM32_HSE_BYPASS + +/* + * MCU type as defined in the ST header. + */ +#define STM32F303xC + +/* + * IO pins assignments. + */ +#define GPIOA_PIN0 0U +#define GPIOA_PIN1 1U +#define GPIOA_PIN2 2U +#define GPIOA_PIN3 3U +#define GPIOA_PIN4 4U +#define GPIOA_PIN5 5U +#define GPIOA_PIN6 6U +#define GPIOA_PIN7 7U +#define GPIOA_PIN8 8U +#define GPIOA_PIN9 9U +#define GPIOA_PIN10 10U +#define GPIOA_USB_DM 11U +#define GPIOA_USB_DP 12U +#define GPIOA_SWDIO 13U +#define GPIOA_SWCLK 14U +#define GPIOA_PIN15 15U + +#define GPIOB_PIN0 0U +#define GPIOB_PIN1 1U +#define GPIOB_PIN2 2U +#define GPIOB_PIN3 3U +#define GPIOB_PIN4 4U +#define GPIOB_PIN5 5U +#define GPIOB_PIN6 6U +#define GPIOB_PIN7 7U +#define GPIOB_PIN8 8U +#define GPIOB_PIN9 9U +#define GPIOB_PIN10 10U +#define GPIOB_PIN11 11U +#define GPIOB_PIN12 12U +#define GPIOB_PIN13 13U +#define GPIOB_PIN14 14U +#define GPIOB_PIN15 15U + +#define GPIOC_PIN0 0U +#define GPIOC_PIN1 1U +#define GPIOC_PIN2 2U +#define GPIOC_PIN3 3U +#define GPIOC_PIN4 4U +#define GPIOC_PIN5 5U +#define GPIOC_PIN6 6U +#define GPIOC_PIN7 7U +#define GPIOC_PIN8 8U +#define GPIOC_PIN9 9U +#define GPIOC_PIN10 10U +#define GPIOC_PIN11 11U +#define GPIOC_PIN12 12U +#define GPIOC_PIN13 13U +#define GPIOC_PIN14 14U +#define GPIOC_PIN15 15U + +#define GPIOD_PIN0 0U +#define GPIOD_PIN1 1U +#define GPIOD_PIN2 2U +#define GPIOD_PIN3 3U +#define GPIOD_PIN4 4U +#define GPIOD_PIN5 5U +#define GPIOD_PIN6 6U +#define GPIOD_PIN7 7U +#define GPIOD_PIN8 8U +#define GPIOD_PIN9 9U +#define GPIOD_PIN10 10U +#define GPIOD_PIN11 11U +#define GPIOD_PIN12 12U +#define GPIOD_PIN13 13U +#define GPIOD_PIN14 14U +#define GPIOD_PIN15 15U + +#define GPIOE_PIN0 0U +#define GPIOE_PIN1 1U +#define GPIOE_PIN2 2U +#define GPIOE_PIN3 3U +#define GPIOE_PIN4 4U +#define GPIOE_PIN5 5U +#define GPIOE_PIN6 6U +#define GPIOE_PIN7 7U +#define GPIOE_PIN8 8U +#define GPIOE_PIN9 9U +#define GPIOE_PIN10 10U +#define GPIOE_PIN11 11U +#define GPIOE_PIN12 12U +#define GPIOE_PIN13 13U +#define GPIOE_PIN14 14U +#define GPIOE_PIN15 15U + +#define GPIOF_I2C2_SDA 0U +#define GPIOF_I2C2_SCL 1U +#define GPIOF_PIN2 2U +#define GPIOF_PIN3 3U +#define GPIOF_PIN4 4U +#define GPIOF_PIN5 5U +#define GPIOF_PIN6 6U +#define GPIOF_PIN7 7U +#define GPIOF_PIN8 8U +#define GPIOF_PIN9 9U +#define GPIOF_PIN10 10U +#define GPIOF_PIN11 11U +#define GPIOF_PIN12 12U +#define GPIOF_PIN13 13U +#define GPIOF_PIN14 14U +#define GPIOF_PIN15 15U + +#define GPIOG_PIN0 0U +#define GPIOG_PIN1 1U +#define GPIOG_PIN2 2U +#define GPIOG_PIN3 3U +#define GPIOG_PIN4 4U +#define GPIOG_PIN5 5U +#define GPIOG_PIN6 6U +#define GPIOG_PIN7 7U +#define GPIOG_PIN8 8U +#define GPIOG_PIN9 9U +#define GPIOG_PIN10 10U +#define GPIOG_PIN11 11U +#define GPIOG_PIN12 12U +#define GPIOG_PIN13 13U +#define GPIOG_PIN14 14U +#define GPIOG_PIN15 15U + +#define GPIOH_PIN0 0U +#define GPIOH_PIN1 1U +#define GPIOH_PIN2 2U +#define GPIOH_PIN3 3U +#define GPIOH_PIN4 4U +#define GPIOH_PIN5 5U +#define GPIOH_PIN6 6U +#define GPIOH_PIN7 7U +#define GPIOH_PIN8 8U +#define GPIOH_PIN9 9U +#define GPIOH_PIN10 10U +#define GPIOH_PIN11 11U +#define GPIOH_PIN12 12U +#define GPIOH_PIN13 13U +#define GPIOH_PIN14 14U +#define GPIOH_PIN15 15U + +/* + * IO lines assignments. + */ +#define LINE_L3GD20_SDI PAL_LINE(GPIOA, 7U) +#define LINE_USB_DM PAL_LINE(GPIOA, 11U) +#define LINE_USB_DP PAL_LINE(GPIOA, 12U) +#define LINE_SWDIO PAL_LINE(GPIOA, 13U) +#define LINE_SWCLK PAL_LINE(GPIOA, 14U) + +#define LINE_PIN6 PAL_LINE(GPIOF, 0U) +#define LINE_PIN7 PAL_LINE(GPIOF, 1U) + +#define LINE_CAPS_LOCK PAL_LINE(GPIOB, 7U) + + +/* + * I/O ports initial setup, this configuration is established soon after reset + * in the initialization code. + * Please refer to the STM32 Reference Manual for details. + */ +#define PIN_MODE_INPUT(n) (0U << ((n) * 2U)) +#define PIN_MODE_OUTPUT(n) (1U << ((n) * 2U)) +#define PIN_MODE_ALTERNATE(n) (2U << ((n) * 2U)) +#define PIN_MODE_ANALOG(n) (3U << ((n) * 2U)) +#define PIN_ODR_LOW(n) (0U << (n)) +#define PIN_ODR_HIGH(n) (1U << (n)) +#define PIN_OTYPE_PUSHPULL(n) (0U << (n)) +#define PIN_OTYPE_OPENDRAIN(n) (1U << (n)) +#define PIN_OSPEED_VERYLOW(n) (0U << ((n) * 2U)) +#define PIN_OSPEED_LOW(n) (1U << ((n) * 2U)) +#define PIN_OSPEED_MEDIUM(n) (2U << ((n) * 2U)) +#define PIN_OSPEED_HIGH(n) (3U << ((n) * 2U)) +#define PIN_PUPDR_FLOATING(n) (0U << ((n) * 2U)) +#define PIN_PUPDR_PULLUP(n) (1U << ((n) * 2U)) +#define PIN_PUPDR_PULLDOWN(n) (2U << ((n) * 2U)) +#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) + +/* + * GPIOA setup: + * + * PA0 - NC + * PA1 - NC + * PA2 - COL1 + * PA3 - COL2 + * PA4 - SPEAKER1 + * PA5 - SPEAKER2 + * PA6 - COL3 + * PA7 - COL8 + * PA8 - COL6 + * PA9 - COL7 + * PA10 - ROW5 + * PA11 - USB_DM (alternate 14). + * PA12 - USB_DP (alternate 14). + * PA13 - SWDIO (alternate 0). + * PA14 - SWCLK (alternate 0). + * PA15 - ROW4 + */ +#define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_PIN0) | \ + PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_INPUT(GPIOA_PIN2) | \ + PIN_MODE_INPUT(GPIOA_PIN3) | \ + PIN_MODE_INPUT(GPIOA_PIN4) | \ + PIN_MODE_INPUT(GPIOA_PIN5) | \ + PIN_MODE_INPUT(GPIOA_PIN6) | \ + PIN_MODE_INPUT(GPIOA_PIN7) | \ + PIN_MODE_INPUT(GPIOA_PIN8) | \ + PIN_MODE_INPUT(GPIOA_PIN9) | \ + PIN_MODE_INPUT(GPIOA_PIN10) | \ + PIN_MODE_ALTERNATE(GPIOA_USB_DM) | \ + PIN_MODE_ALTERNATE(GPIOA_USB_DP) | \ + PIN_MODE_ALTERNATE(GPIOA_SWDIO) | \ + PIN_MODE_ALTERNATE(GPIOA_SWCLK) | \ + PIN_MODE_INPUT(GPIOA_PIN15)) +#define VAL_GPIOA_OTYPER (PIN_OTYPE_PUSHPULL(GPIOA_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOA_USB_DM) | \ + PIN_OTYPE_PUSHPULL(GPIOA_USB_DP) | \ + PIN_OTYPE_PUSHPULL(GPIOA_SWDIO) | \ + PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN15)) +#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOA_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN10) | \ + PIN_OSPEED_HIGH(GPIOA_USB_DM) | \ + PIN_OSPEED_VERYLOW(GPIOA_USB_DP) | \ + PIN_OSPEED_HIGH(GPIOA_SWDIO) | \ + PIN_OSPEED_HIGH(GPIOA_SWCLK) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN15)) +#define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN4) | \ + PIN_PUPDR_FLOATING(GPIOA_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN6) | \ + PIN_PUPDR_FLOATING(GPIOA_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN10) | \ + PIN_PUPDR_FLOATING(GPIOA_USB_DM) | \ + PIN_PUPDR_FLOATING(GPIOA_USB_DP) | \ + PIN_PUPDR_PULLUP(GPIOA_SWDIO) | \ + PIN_PUPDR_PULLDOWN(GPIOA_SWCLK) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN15)) +#define VAL_GPIOA_ODR (PIN_ODR_HIGH(GPIOA_PIN0) | \ + PIN_ODR_HIGH(GPIOA_PIN1) | \ + PIN_ODR_HIGH(GPIOA_PIN2) | \ + PIN_ODR_HIGH(GPIOA_PIN3) | \ + PIN_ODR_HIGH(GPIOA_PIN4) | \ + PIN_ODR_HIGH(GPIOA_PIN5) | \ + PIN_ODR_HIGH(GPIOA_PIN6) | \ + PIN_ODR_HIGH(GPIOA_PIN7) | \ + PIN_ODR_HIGH(GPIOA_PIN8) | \ + PIN_ODR_HIGH(GPIOA_PIN9) | \ + PIN_ODR_HIGH(GPIOA_PIN10) | \ + PIN_ODR_HIGH(GPIOA_USB_DM) | \ + PIN_ODR_HIGH(GPIOA_USB_DP) | \ + PIN_ODR_HIGH(GPIOA_SWDIO) | \ + PIN_ODR_HIGH(GPIOA_SWCLK) | \ + PIN_ODR_HIGH(GPIOA_PIN15)) +#define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PIN0, 0) | \ + PIN_AFIO_AF(GPIOA_PIN1, 0) | \ + PIN_AFIO_AF(GPIOA_PIN2, 0) | \ + PIN_AFIO_AF(GPIOA_PIN3, 0) | \ + PIN_AFIO_AF(GPIOA_PIN4, 0) | \ + PIN_AFIO_AF(GPIOA_PIN5, 5) | \ + PIN_AFIO_AF(GPIOA_PIN6, 5) | \ + PIN_AFIO_AF(GPIOA_PIN7, 5)) +#define VAL_GPIOA_AFRH (PIN_AFIO_AF(GPIOA_PIN8, 0) | \ + PIN_AFIO_AF(GPIOA_PIN9, 0) | \ + PIN_AFIO_AF(GPIOA_PIN10, 0) | \ + PIN_AFIO_AF(GPIOA_USB_DM, 14) | \ + PIN_AFIO_AF(GPIOA_USB_DP, 14) | \ + PIN_AFIO_AF(GPIOA_SWDIO, 0) | \ + PIN_AFIO_AF(GPIOA_SWCLK, 0) | \ + PIN_AFIO_AF(GPIOA_PIN15, 0)) + +/* + * GPIOB setup: + * + * PB0 - PIN0 (input pullup). + * PB1 - PIN1 (input pullup). + * PB2 - PIN2 (input pullup). + * PB3 - PIN3 (alternate 0). + * PB4 - PIN4 (input pullup). + * PB5 - PIN5 (input pullup). + * PB6 - PIN6 LSM303DLHC_SCL (alternate 4). + * PB7 - PIN7 LSM303DLHC_SDA (alternate 4). + * PB8 - PIN8 (input pullup). + * PB9 - PIN9 (input pullup). + * PB10 - PIN10 (input pullup). + * PB11 - PIN11 (input pullup). + * PB12 - PIN12 (input pullup). + * PB13 - PIN13 (input pullup). + * PB14 - PIN14 (input pullup). + * PB15 - PIN15 (input pullup). + */ +#define VAL_GPIOB_MODER (PIN_MODE_INPUT(GPIOB_PIN0) | \ + PIN_MODE_INPUT(GPIOB_PIN1) | \ + PIN_MODE_INPUT(GPIOB_PIN2) | \ + PIN_MODE_ALTERNATE(GPIOB_PIN3) | \ + PIN_MODE_INPUT(GPIOB_PIN4) | \ + PIN_MODE_INPUT(GPIOB_PIN5) | \ + PIN_MODE_ALTERNATE(GPIOB_PIN6) | \ + PIN_MODE_OUTPUT(GPIOB_PIN7) | \ + PIN_MODE_INPUT(GPIOB_PIN8) | \ + PIN_MODE_INPUT(GPIOB_PIN9) | \ + PIN_MODE_INPUT(GPIOB_PIN10) | \ + PIN_MODE_INPUT(GPIOB_PIN11) | \ + PIN_MODE_INPUT(GPIOB_PIN12) | \ + PIN_MODE_INPUT(GPIOB_PIN13) | \ + PIN_MODE_INPUT(GPIOB_PIN14) | \ + PIN_MODE_INPUT(GPIOB_PIN15)) +#define VAL_GPIOB_OTYPER (PIN_OTYPE_PUSHPULL(GPIOB_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN5) | \ + PIN_OTYPE_OPENDRAIN(GPIOB_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN15)) +#define VAL_GPIOB_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOB_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN2) | \ + PIN_OSPEED_HIGH(GPIOB_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN5) | \ + PIN_OSPEED_HIGH(GPIOB_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN15)) +#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLUP(GPIOB_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN2) | \ + PIN_PUPDR_FLOATING(GPIOB_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN5) | \ + PIN_PUPDR_FLOATING(GPIOB_PIN6) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN15)) +#define VAL_GPIOB_ODR (PIN_ODR_HIGH(GPIOB_PIN0) | \ + PIN_ODR_HIGH(GPIOB_PIN1) | \ + PIN_ODR_HIGH(GPIOB_PIN2) | \ + PIN_ODR_HIGH(GPIOB_PIN3) | \ + PIN_ODR_HIGH(GPIOB_PIN4) | \ + PIN_ODR_HIGH(GPIOB_PIN5) | \ + PIN_ODR_HIGH(GPIOB_PIN6) | \ + PIN_ODR_LOW(GPIOB_PIN7) | \ + PIN_ODR_HIGH(GPIOB_PIN8) | \ + PIN_ODR_HIGH(GPIOB_PIN9) | \ + PIN_ODR_HIGH(GPIOB_PIN10) | \ + PIN_ODR_HIGH(GPIOB_PIN11) | \ + PIN_ODR_HIGH(GPIOB_PIN12) | \ + PIN_ODR_HIGH(GPIOB_PIN13) | \ + PIN_ODR_HIGH(GPIOB_PIN14) | \ + PIN_ODR_HIGH(GPIOB_PIN15)) +#define VAL_GPIOB_AFRL (PIN_AFIO_AF(GPIOB_PIN0, 0) | \ + PIN_AFIO_AF(GPIOB_PIN1, 0) | \ + PIN_AFIO_AF(GPIOB_PIN2, 0) | \ + PIN_AFIO_AF(GPIOB_PIN3, 0) | \ + PIN_AFIO_AF(GPIOB_PIN4, 0) | \ + PIN_AFIO_AF(GPIOB_PIN5, 0) | \ + PIN_AFIO_AF(GPIOB_PIN6, 4) | \ + PIN_AFIO_AF(GPIOB_PIN7, 0)) +#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_PIN8, 0) | \ + PIN_AFIO_AF(GPIOB_PIN9, 0) | \ + PIN_AFIO_AF(GPIOB_PIN10, 0) | \ + PIN_AFIO_AF(GPIOB_PIN11, 0) | \ + PIN_AFIO_AF(GPIOB_PIN12, 0) | \ + PIN_AFIO_AF(GPIOB_PIN13, 0) | \ + PIN_AFIO_AF(GPIOB_PIN14, 0) | \ + PIN_AFIO_AF(GPIOB_PIN15, 0)) + +/* + * GPIOC setup: + * + * PC0 - PIN0 (input pullup). + * PC1 - PIN1 (input pullup). + * PC2 - PIN2 (input pullup). + * PC3 - PIN3 (input pullup). + * PC4 - PIN4 (input pullup). + * PC5 - PIN5 (input pullup). + * PC6 - PIN6 (input pullup). + * PC7 - PIN7 (input pullup). + * PC8 - PIN8 (input pullup). + * PC9 - PIN9 (input pullup). + * PC10 - PIN10 (input pullup). + * PC11 - PIN11 (input pullup). + * PC12 - PIN12 (input pullup). + * PC13 - PIN13 (input pullup). + * PC14 - PIN14 (input floating). + * PC15 - PIN15 (input floating). + */ +#define VAL_GPIOC_MODER (PIN_MODE_INPUT(GPIOC_PIN0) | \ + PIN_MODE_INPUT(GPIOC_PIN1) | \ + PIN_MODE_INPUT(GPIOC_PIN2) | \ + PIN_MODE_INPUT(GPIOC_PIN3) | \ + PIN_MODE_INPUT(GPIOC_PIN4) | \ + PIN_MODE_INPUT(GPIOC_PIN5) | \ + PIN_MODE_INPUT(GPIOC_PIN6) | \ + PIN_MODE_INPUT(GPIOC_PIN7) | \ + PIN_MODE_INPUT(GPIOC_PIN8) | \ + PIN_MODE_INPUT(GPIOC_PIN9) | \ + PIN_MODE_INPUT(GPIOC_PIN10) | \ + PIN_MODE_INPUT(GPIOC_PIN11) | \ + PIN_MODE_INPUT(GPIOC_PIN12) | \ + PIN_MODE_INPUT(GPIOC_PIN13) | \ + PIN_MODE_INPUT(GPIOC_PIN14) | \ + PIN_MODE_INPUT(GPIOC_PIN15)) +#define VAL_GPIOC_OTYPER (PIN_OTYPE_PUSHPULL(GPIOC_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN15)) +#define VAL_GPIOC_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOC_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN13) | \ + PIN_OSPEED_HIGH(GPIOC_PIN14) | \ + PIN_OSPEED_HIGH(GPIOC_PIN15)) +#define VAL_GPIOC_PUPDR (PIN_PUPDR_PULLUP(GPIOC_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN13) | \ + PIN_PUPDR_FLOATING(GPIOC_PIN14) | \ + PIN_PUPDR_FLOATING(GPIOC_PIN15)) +#define VAL_GPIOC_ODR (PIN_ODR_HIGH(GPIOC_PIN0) | \ + PIN_ODR_HIGH(GPIOC_PIN1) | \ + PIN_ODR_HIGH(GPIOC_PIN2) | \ + PIN_ODR_HIGH(GPIOC_PIN3) | \ + PIN_ODR_HIGH(GPIOC_PIN4) | \ + PIN_ODR_HIGH(GPIOC_PIN5) | \ + PIN_ODR_HIGH(GPIOC_PIN6) | \ + PIN_ODR_HIGH(GPIOC_PIN7) | \ + PIN_ODR_HIGH(GPIOC_PIN8) | \ + PIN_ODR_HIGH(GPIOC_PIN9) | \ + PIN_ODR_HIGH(GPIOC_PIN10) | \ + PIN_ODR_HIGH(GPIOC_PIN11) | \ + PIN_ODR_HIGH(GPIOC_PIN12) | \ + PIN_ODR_HIGH(GPIOC_PIN13) | \ + PIN_ODR_HIGH(GPIOC_PIN14) | \ + PIN_ODR_HIGH(GPIOC_PIN15)) +#define VAL_GPIOC_AFRL (PIN_AFIO_AF(GPIOC_PIN0, 0) | \ + PIN_AFIO_AF(GPIOC_PIN1, 0) | \ + PIN_AFIO_AF(GPIOC_PIN2, 0) | \ + PIN_AFIO_AF(GPIOC_PIN3, 0) | \ + PIN_AFIO_AF(GPIOC_PIN4, 0) | \ + PIN_AFIO_AF(GPIOC_PIN5, 0) | \ + PIN_AFIO_AF(GPIOC_PIN6, 0) | \ + PIN_AFIO_AF(GPIOC_PIN7, 0)) +#define VAL_GPIOC_AFRH (PIN_AFIO_AF(GPIOC_PIN8, 0) | \ + PIN_AFIO_AF(GPIOC_PIN9, 0) | \ + PIN_AFIO_AF(GPIOC_PIN10, 0) | \ + PIN_AFIO_AF(GPIOC_PIN11, 0) | \ + PIN_AFIO_AF(GPIOC_PIN12, 0) | \ + PIN_AFIO_AF(GPIOC_PIN13, 0) | \ + PIN_AFIO_AF(GPIOC_PIN14, 0) | \ + PIN_AFIO_AF(GPIOC_PIN15, 0)) + +/* + * GPIOD setup: + * + * PD0 - PIN0 (input pullup). + * PD1 - PIN1 (input pullup). + * PD2 - PIN2 (input pullup). + * PD3 - PIN3 (input pullup). + * PD4 - PIN4 (input pullup). + * PD5 - PIN5 (input pullup). + * PD6 - PIN6 (input pullup). + * PD7 - PIN7 (input pullup). + * PD8 - PIN8 (input pullup). + * PD9 - PIN9 (input pullup). + * PD11 - PIN10 (input pullup). + * PD11 - PIN11 (input pullup). + * PD12 - PIN12 (input pullup). + * PD13 - PIN13 (input pullup). + * PD14 - PIN14 (input pullup). + * PD15 - PIN15 (input pullup). + */ +#define VAL_GPIOD_MODER (PIN_MODE_INPUT(GPIOD_PIN0) | \ + PIN_MODE_INPUT(GPIOD_PIN1) | \ + PIN_MODE_INPUT(GPIOD_PIN2) | \ + PIN_MODE_INPUT(GPIOD_PIN3) | \ + PIN_MODE_INPUT(GPIOD_PIN4) | \ + PIN_MODE_INPUT(GPIOD_PIN5) | \ + PIN_MODE_INPUT(GPIOD_PIN6) | \ + PIN_MODE_INPUT(GPIOD_PIN7) | \ + PIN_MODE_INPUT(GPIOD_PIN8) | \ + PIN_MODE_INPUT(GPIOD_PIN9) | \ + PIN_MODE_INPUT(GPIOD_PIN10) | \ + PIN_MODE_INPUT(GPIOD_PIN11) | \ + PIN_MODE_INPUT(GPIOD_PIN12) | \ + PIN_MODE_INPUT(GPIOD_PIN13) | \ + PIN_MODE_INPUT(GPIOD_PIN14) | \ + PIN_MODE_INPUT(GPIOD_PIN15)) +#define VAL_GPIOD_OTYPER (PIN_OTYPE_PUSHPULL(GPIOD_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN15)) +#define VAL_GPIOD_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOD_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN15)) +#define VAL_GPIOD_PUPDR (PIN_PUPDR_PULLUP(GPIOD_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN15)) +#define VAL_GPIOD_ODR (PIN_ODR_HIGH(GPIOD_PIN0) | \ + PIN_ODR_HIGH(GPIOD_PIN1) | \ + PIN_ODR_HIGH(GPIOD_PIN2) | \ + PIN_ODR_HIGH(GPIOD_PIN3) | \ + PIN_ODR_HIGH(GPIOD_PIN4) | \ + PIN_ODR_HIGH(GPIOD_PIN5) | \ + PIN_ODR_HIGH(GPIOD_PIN6) | \ + PIN_ODR_HIGH(GPIOD_PIN7) | \ + PIN_ODR_HIGH(GPIOD_PIN8) | \ + PIN_ODR_HIGH(GPIOD_PIN9) | \ + PIN_ODR_HIGH(GPIOD_PIN10) | \ + PIN_ODR_HIGH(GPIOD_PIN11) | \ + PIN_ODR_HIGH(GPIOD_PIN12) | \ + PIN_ODR_HIGH(GPIOD_PIN13) | \ + PIN_ODR_HIGH(GPIOD_PIN14) | \ + PIN_ODR_HIGH(GPIOD_PIN15)) +#define VAL_GPIOD_AFRL (PIN_AFIO_AF(GPIOD_PIN0, 0) | \ + PIN_AFIO_AF(GPIOD_PIN1, 0) | \ + PIN_AFIO_AF(GPIOD_PIN2, 0) | \ + PIN_AFIO_AF(GPIOD_PIN3, 0) | \ + PIN_AFIO_AF(GPIOD_PIN4, 0) | \ + PIN_AFIO_AF(GPIOD_PIN5, 0) | \ + PIN_AFIO_AF(GPIOD_PIN6, 0) | \ + PIN_AFIO_AF(GPIOD_PIN7, 0)) +#define VAL_GPIOD_AFRH (PIN_AFIO_AF(GPIOD_PIN8, 0) | \ + PIN_AFIO_AF(GPIOD_PIN9, 0) | \ + PIN_AFIO_AF(GPIOD_PIN10, 0) | \ + PIN_AFIO_AF(GPIOD_PIN11, 0) | \ + PIN_AFIO_AF(GPIOD_PIN12, 0) | \ + PIN_AFIO_AF(GPIOD_PIN13, 0) | \ + PIN_AFIO_AF(GPIOD_PIN14, 0) | \ + PIN_AFIO_AF(GPIOD_PIN15, 0)) + +/* + * GPIOE setup: + * + * PE0 - PIN0 (input pullup). + * PE1 - PIN1 (input pullup). + * PE2 - PIN2 (input pullup). + * PE3 - PIN3 L3GD20_CS (output pushpull maximum). + * PE4 - PIN4 (input pullup). + * PE5 - PIN5 (input pullup). + * PE6 - PIN6 (input pullup). + * PE7 - PIN7 (input pullup). + * PE8 - PIN8 (output pushpull maximum). + * PE9 - PIN9 (output pushpull maximum). + * PE10 - PIN10 (output pushpull maximum). + * PE11 - PIN11 (output pushpull maximum). + * PE12 - PIN12 (output pushpull maximum). + * PE13 - PIN13 (output pushpull maximum). + * PE14 - PIN14 (output pushpull maximum). + * PE15 - PIN15 (output pushpull maximum). + */ +#define VAL_GPIOE_MODER (PIN_MODE_INPUT(GPIOE_PIN0) | \ + PIN_MODE_INPUT(GPIOE_PIN1) | \ + PIN_MODE_INPUT(GPIOE_PIN2) |\ + PIN_MODE_OUTPUT(GPIOE_PIN3) | \ + PIN_MODE_INPUT(GPIOE_PIN4) |\ + PIN_MODE_INPUT(GPIOE_PIN5) |\ + PIN_MODE_INPUT(GPIOE_PIN6) | \ + PIN_MODE_INPUT(GPIOE_PIN7) | \ + PIN_MODE_OUTPUT(GPIOE_PIN8) | \ + PIN_MODE_OUTPUT(GPIOE_PIN9) | \ + PIN_MODE_OUTPUT(GPIOE_PIN10) | \ + PIN_MODE_OUTPUT(GPIOE_PIN11) | \ + PIN_MODE_OUTPUT(GPIOE_PIN12) | \ + PIN_MODE_OUTPUT(GPIOE_PIN13) | \ + PIN_MODE_OUTPUT(GPIOE_PIN14) | \ + PIN_MODE_OUTPUT(GPIOE_PIN15)) +#define VAL_GPIOE_OTYPER (PIN_OTYPE_PUSHPULL(GPIOE_PIN0) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN1) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN2) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN4) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN5) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN10) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN14) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN15)) +#define VAL_GPIOE_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOE_PIN0) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN1) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN2) |\ + PIN_OSPEED_HIGH(GPIOE_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOE_PIN4) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN5) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOE_PIN7) | \ + PIN_OSPEED_HIGH(GPIOE_PIN8) | \ + PIN_OSPEED_HIGH(GPIOE_PIN9) | \ + PIN_OSPEED_HIGH(GPIOE_PIN10) | \ + PIN_OSPEED_HIGH(GPIOE_PIN11) | \ + PIN_OSPEED_HIGH(GPIOE_PIN12) | \ + PIN_OSPEED_HIGH(GPIOE_PIN13) | \ + PIN_OSPEED_HIGH(GPIOE_PIN14) | \ + PIN_OSPEED_HIGH(GPIOE_PIN15)) +#define VAL_GPIOE_PUPDR (PIN_PUPDR_PULLUP(GPIOE_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN2) |\ + PIN_PUPDR_FLOATING(GPIOE_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN4) |\ + PIN_PUPDR_PULLUP(GPIOE_PIN5) |\ + PIN_PUPDR_PULLUP(GPIOE_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN10) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN12) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN13) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN14) |\ + PIN_PUPDR_FLOATING(GPIOE_PIN15)) +#define VAL_GPIOE_ODR (PIN_ODR_HIGH(GPIOE_PIN0) | \ + PIN_ODR_HIGH(GPIOE_PIN1) | \ + PIN_ODR_HIGH(GPIOE_PIN2) | \ + PIN_ODR_HIGH(GPIOE_PIN3) | \ + PIN_ODR_HIGH(GPIOE_PIN4) | \ + PIN_ODR_HIGH(GPIOE_PIN5) | \ + PIN_ODR_HIGH(GPIOE_PIN6) | \ + PIN_ODR_HIGH(GPIOE_PIN7) | \ + PIN_ODR_LOW(GPIOE_PIN8) | \ + PIN_ODR_LOW(GPIOE_PIN9) | \ + PIN_ODR_LOW(GPIOE_PIN10) | \ + PIN_ODR_LOW(GPIOE_PIN11) | \ + PIN_ODR_LOW(GPIOE_PIN12) | \ + PIN_ODR_LOW(GPIOE_PIN13) | \ + PIN_ODR_LOW(GPIOE_PIN14) | \ + PIN_ODR_LOW(GPIOE_PIN15)) +#define VAL_GPIOE_AFRL (PIN_AFIO_AF(GPIOE_PIN0, 0) | \ + PIN_AFIO_AF(GPIOE_PIN1, 0) | \ + PIN_AFIO_AF(GPIOE_PIN2, 0) |\ + PIN_AFIO_AF(GPIOE_PIN3, 0) | \ + PIN_AFIO_AF(GPIOE_PIN4, 0) |\ + PIN_AFIO_AF(GPIOE_PIN5, 0) |\ + PIN_AFIO_AF(GPIOE_PIN6, 0) | \ + PIN_AFIO_AF(GPIOE_PIN7, 0)) +#define VAL_GPIOE_AFRH (PIN_AFIO_AF(GPIOE_PIN8, 0) | \ + PIN_AFIO_AF(GPIOE_PIN9, 0) | \ + PIN_AFIO_AF(GPIOE_PIN10, 0) | \ + PIN_AFIO_AF(GPIOE_PIN11, 0) | \ + PIN_AFIO_AF(GPIOE_PIN12, 0) | \ + PIN_AFIO_AF(GPIOE_PIN13, 0) | \ + PIN_AFIO_AF(GPIOE_PIN14, 0) | \ + PIN_AFIO_AF(GPIOE_PIN15, 0)) + +/* + * GPIOF setup: + * + * PF0 - I2C2_SDA (input floating). + * PF1 - I2C2_SCL (input floating). + * PF2 - PIN2 (input pullup). + * PF3 - PIN3 (input pullup). + * PF4 - PIN4 (input pullup). + * PF5 - PIN5 (input pullup). + * PF6 - PIN6 (input pullup). + * PF7 - PIN7 (input pullup). + * PF8 - PIN8 (input pullup). + * PF9 - PIN9 (input pullup). + * PF10 - PIN10 (input pullup). + * PF11 - PIN11 (input pullup). + * PF12 - PIN12 (input pullup). + * PF13 - PIN13 (input pullup). + * PF14 - PIN14 (input pullup). + * PF15 - PIN15 (input pullup). + */ +#define VAL_GPIOF_MODER (PIN_MODE_INPUT(GPIOF_I2C2_SDA) | \ + PIN_MODE_INPUT(GPIOF_I2C2_SCL) | \ + PIN_MODE_INPUT(GPIOF_PIN2) | \ + PIN_MODE_INPUT(GPIOF_PIN3) | \ + PIN_MODE_INPUT(GPIOF_PIN4) | \ + PIN_MODE_INPUT(GPIOF_PIN5) | \ + PIN_MODE_INPUT(GPIOF_PIN6) | \ + PIN_MODE_INPUT(GPIOF_PIN7) | \ + PIN_MODE_INPUT(GPIOF_PIN8) | \ + PIN_MODE_INPUT(GPIOF_PIN9) | \ + PIN_MODE_INPUT(GPIOF_PIN10) | \ + PIN_MODE_INPUT(GPIOF_PIN11) | \ + PIN_MODE_INPUT(GPIOF_PIN12) | \ + PIN_MODE_INPUT(GPIOF_PIN13) | \ + PIN_MODE_INPUT(GPIOF_PIN14) | \ + PIN_MODE_INPUT(GPIOF_PIN15)) +#define VAL_GPIOF_OTYPER (PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SDA) | \ + PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SCL) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN15)) +#define VAL_GPIOF_OSPEEDR (PIN_OSPEED_HIGH(GPIOF_I2C2_SDA) | \ + PIN_OSPEED_HIGH(GPIOF_I2C2_SCL) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN15)) +#define VAL_GPIOF_PUPDR (PIN_PUPDR_FLOATING(GPIOF_I2C2_SDA) | \ + PIN_PUPDR_FLOATING(GPIOF_I2C2_SCL) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN15)) +#define VAL_GPIOF_ODR (PIN_ODR_HIGH(GPIOF_I2C2_SDA) | \ + PIN_ODR_HIGH(GPIOF_I2C2_SCL) | \ + PIN_ODR_HIGH(GPIOF_PIN2) | \ + PIN_ODR_HIGH(GPIOF_PIN3) | \ + PIN_ODR_HIGH(GPIOF_PIN4) | \ + PIN_ODR_HIGH(GPIOF_PIN5) | \ + PIN_ODR_HIGH(GPIOF_PIN6) | \ + PIN_ODR_HIGH(GPIOF_PIN7) | \ + PIN_ODR_HIGH(GPIOF_PIN8) | \ + PIN_ODR_HIGH(GPIOF_PIN9) | \ + PIN_ODR_HIGH(GPIOF_PIN10) | \ + PIN_ODR_HIGH(GPIOF_PIN11) | \ + PIN_ODR_HIGH(GPIOF_PIN12) | \ + PIN_ODR_HIGH(GPIOF_PIN13) | \ + PIN_ODR_HIGH(GPIOF_PIN14) | \ + PIN_ODR_HIGH(GPIOF_PIN15)) +#define VAL_GPIOF_AFRL (PIN_AFIO_AF(GPIOF_I2C2_SDA, 0) | \ + PIN_AFIO_AF(GPIOF_I2C2_SCL, 0) | \ + PIN_AFIO_AF(GPIOF_PIN2, 0) | \ + PIN_AFIO_AF(GPIOF_PIN3, 0) | \ + PIN_AFIO_AF(GPIOF_PIN4, 0) | \ + PIN_AFIO_AF(GPIOF_PIN5, 0) | \ + PIN_AFIO_AF(GPIOF_PIN6, 0) | \ + PIN_AFIO_AF(GPIOF_PIN7, 0)) +#define VAL_GPIOF_AFRH (PIN_AFIO_AF(GPIOF_PIN8, 0) | \ + PIN_AFIO_AF(GPIOF_PIN9, 0) | \ + PIN_AFIO_AF(GPIOF_PIN10, 0) | \ + PIN_AFIO_AF(GPIOF_PIN11, 0) | \ + PIN_AFIO_AF(GPIOF_PIN12, 0) | \ + PIN_AFIO_AF(GPIOF_PIN13, 0) | \ + PIN_AFIO_AF(GPIOF_PIN14, 0) | \ + PIN_AFIO_AF(GPIOF_PIN15, 0)) + +/* + * GPIOG setup: + * + * PG0 - PIN0 (input pullup). + * PG1 - PIN1 (input pullup). + * PG2 - PIN2 (input pullup). + * PG3 - PIN3 (input pullup). + * PG4 - PIN4 (input pullup). + * PG5 - PIN5 (input pullup). + * PG6 - PIN6 (input pullup). + * PG7 - PIN7 (input pullup). + * PG8 - PIN8 (input pullup). + * PG9 - PIN9 (input pullup). + * PG10 - PIN10 (input pullup). + * PG11 - PIN11 (input pullup). + * PG12 - PIN12 (input pullup). + * PG13 - PIN13 (input pullup). + * PG14 - PIN14 (input pullup). + * PG15 - PIN15 (input pullup). + */ +#define VAL_GPIOG_MODER (PIN_MODE_INPUT(GPIOG_PIN0) | \ + PIN_MODE_INPUT(GPIOG_PIN1) | \ + PIN_MODE_INPUT(GPIOG_PIN2) | \ + PIN_MODE_INPUT(GPIOG_PIN3) | \ + PIN_MODE_INPUT(GPIOG_PIN4) | \ + PIN_MODE_INPUT(GPIOG_PIN5) | \ + PIN_MODE_INPUT(GPIOG_PIN6) | \ + PIN_MODE_INPUT(GPIOG_PIN7) | \ + PIN_MODE_INPUT(GPIOG_PIN8) | \ + PIN_MODE_INPUT(GPIOG_PIN9) | \ + PIN_MODE_INPUT(GPIOG_PIN10) | \ + PIN_MODE_INPUT(GPIOG_PIN11) | \ + PIN_MODE_INPUT(GPIOG_PIN12) | \ + PIN_MODE_INPUT(GPIOG_PIN13) | \ + PIN_MODE_INPUT(GPIOG_PIN14) | \ + PIN_MODE_INPUT(GPIOG_PIN15)) +#define VAL_GPIOG_OTYPER (PIN_OTYPE_PUSHPULL(GPIOG_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN15)) +#define VAL_GPIOG_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOG_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN15)) +#define VAL_GPIOG_PUPDR (PIN_PUPDR_PULLUP(GPIOG_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN15)) +#define VAL_GPIOG_ODR (PIN_ODR_HIGH(GPIOG_PIN0) | \ + PIN_ODR_HIGH(GPIOG_PIN1) | \ + PIN_ODR_HIGH(GPIOG_PIN2) | \ + PIN_ODR_HIGH(GPIOG_PIN3) | \ + PIN_ODR_HIGH(GPIOG_PIN4) | \ + PIN_ODR_HIGH(GPIOG_PIN5) | \ + PIN_ODR_HIGH(GPIOG_PIN6) | \ + PIN_ODR_HIGH(GPIOG_PIN7) | \ + PIN_ODR_HIGH(GPIOG_PIN8) | \ + PIN_ODR_HIGH(GPIOG_PIN9) | \ + PIN_ODR_HIGH(GPIOG_PIN10) | \ + PIN_ODR_HIGH(GPIOG_PIN11) | \ + PIN_ODR_HIGH(GPIOG_PIN12) | \ + PIN_ODR_HIGH(GPIOG_PIN13) | \ + PIN_ODR_HIGH(GPIOG_PIN14) | \ + PIN_ODR_HIGH(GPIOG_PIN15)) +#define VAL_GPIOG_AFRL (PIN_AFIO_AF(GPIOG_PIN0, 0) | \ + PIN_AFIO_AF(GPIOG_PIN1, 0) | \ + PIN_AFIO_AF(GPIOG_PIN2, 0) | \ + PIN_AFIO_AF(GPIOG_PIN3, 0) | \ + PIN_AFIO_AF(GPIOG_PIN4, 0) | \ + PIN_AFIO_AF(GPIOG_PIN5, 0) | \ + PIN_AFIO_AF(GPIOG_PIN6, 0) | \ + PIN_AFIO_AF(GPIOG_PIN7, 0)) +#define VAL_GPIOG_AFRH (PIN_AFIO_AF(GPIOG_PIN8, 0) | \ + PIN_AFIO_AF(GPIOG_PIN9, 0) | \ + PIN_AFIO_AF(GPIOG_PIN10, 0) | \ + PIN_AFIO_AF(GPIOG_PIN11, 0) | \ + PIN_AFIO_AF(GPIOG_PIN12, 0) | \ + PIN_AFIO_AF(GPIOG_PIN13, 0) | \ + PIN_AFIO_AF(GPIOG_PIN14, 0) | \ + PIN_AFIO_AF(GPIOG_PIN15, 0)) + +/* + * GPIOH setup: + * + * PH0 - PIN0 (input pullup). + * PH1 - PIN1 (input pullup). + * PH2 - PIN2 (input pullup). + * PH3 - PIN3 (input pullup). + * PH4 - PIN4 (input pullup). + * PH5 - PIN5 (input pullup). + * PH6 - PIN6 (input pullup). + * PH7 - PIN7 (input pullup). + * PH8 - PIN8 (input pullup). + * PH9 - PIN9 (input pullup). + * PH10 - PIN10 (input pullup). + * PH11 - PIN11 (input pullup). + * PH12 - PIN12 (input pullup). + * PH13 - PIN13 (input pullup). + * PH14 - PIN14 (input pullup). + * PH15 - PIN15 (input pullup). + */ +#define VAL_GPIOH_MODER (PIN_MODE_INPUT(GPIOH_PIN0) | \ + PIN_MODE_INPUT(GPIOH_PIN1) | \ + PIN_MODE_INPUT(GPIOH_PIN2) | \ + PIN_MODE_INPUT(GPIOH_PIN3) | \ + PIN_MODE_INPUT(GPIOH_PIN4) | \ + PIN_MODE_INPUT(GPIOH_PIN5) | \ + PIN_MODE_INPUT(GPIOH_PIN6) | \ + PIN_MODE_INPUT(GPIOH_PIN7) | \ + PIN_MODE_INPUT(GPIOH_PIN8) | \ + PIN_MODE_INPUT(GPIOH_PIN9) | \ + PIN_MODE_INPUT(GPIOH_PIN10) | \ + PIN_MODE_INPUT(GPIOH_PIN11) | \ + PIN_MODE_INPUT(GPIOH_PIN12) | \ + PIN_MODE_INPUT(GPIOH_PIN13) | \ + PIN_MODE_INPUT(GPIOH_PIN14) | \ + PIN_MODE_INPUT(GPIOH_PIN15)) +#define VAL_GPIOH_OTYPER (PIN_OTYPE_PUSHPULL(GPIOH_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN15)) +#define VAL_GPIOH_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOH_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN15)) +#define VAL_GPIOH_PUPDR (PIN_PUPDR_PULLUP(GPIOH_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN15)) +#define VAL_GPIOH_ODR (PIN_ODR_HIGH(GPIOH_PIN0) | \ + PIN_ODR_HIGH(GPIOH_PIN1) | \ + PIN_ODR_HIGH(GPIOH_PIN2) | \ + PIN_ODR_HIGH(GPIOH_PIN3) | \ + PIN_ODR_HIGH(GPIOH_PIN4) | \ + PIN_ODR_HIGH(GPIOH_PIN5) | \ + PIN_ODR_HIGH(GPIOH_PIN6) | \ + PIN_ODR_HIGH(GPIOH_PIN7) | \ + PIN_ODR_HIGH(GPIOH_PIN8) | \ + PIN_ODR_HIGH(GPIOH_PIN9) | \ + PIN_ODR_HIGH(GPIOH_PIN10) | \ + PIN_ODR_HIGH(GPIOH_PIN11) | \ + PIN_ODR_HIGH(GPIOH_PIN12) | \ + PIN_ODR_HIGH(GPIOH_PIN13) | \ + PIN_ODR_HIGH(GPIOH_PIN14) | \ + PIN_ODR_HIGH(GPIOH_PIN15)) +#define VAL_GPIOH_AFRL (PIN_AFIO_AF(GPIOH_PIN0, 0) | \ + PIN_AFIO_AF(GPIOH_PIN1, 0) | \ + PIN_AFIO_AF(GPIOH_PIN2, 0) | \ + PIN_AFIO_AF(GPIOH_PIN3, 0) | \ + PIN_AFIO_AF(GPIOH_PIN4, 0) | \ + PIN_AFIO_AF(GPIOH_PIN5, 0) | \ + PIN_AFIO_AF(GPIOH_PIN6, 0) | \ + PIN_AFIO_AF(GPIOH_PIN7, 0)) +#define VAL_GPIOH_AFRH (PIN_AFIO_AF(GPIOH_PIN8, 0) | \ + PIN_AFIO_AF(GPIOH_PIN9, 0) | \ + PIN_AFIO_AF(GPIOH_PIN10, 0) | \ + PIN_AFIO_AF(GPIOH_PIN11, 0) | \ + PIN_AFIO_AF(GPIOH_PIN12, 0) | \ + PIN_AFIO_AF(GPIOH_PIN13, 0) | \ + PIN_AFIO_AF(GPIOH_PIN14, 0) | \ + PIN_AFIO_AF(GPIOH_PIN15, 0)) + + +/* + * USB bus activation macro, required by the USB driver. + */ +// #define usb_lld_connect_bus(usbp) +#define usb_lld_connect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_ALTERNATE(14))) +// #define usb_lld_connect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_INPUT) +/* + * USB bus de-activation macro, required by the USB driver. + */ +// #define usb_lld_disconnect_bus(usbp) +#define usb_lld_disconnect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_OUTPUT_PUSHPULL)) +// #define usb_lld_disconnect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 12) + +#if !defined(_FROM_ASM_) +#ifdef __cplusplus +extern "C" { +#endif + void boardInit(void); +#ifdef __cplusplus +} +#endif +#endif /* _FROM_ASM_ */ + +#endif /* _BOARD_H_ */ diff --git a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.mk b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.mk new file mode 100644 index 0000000000..43377629a3 --- /dev/null +++ b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.mk @@ -0,0 +1,5 @@ +# List of all the board related files. +BOARDSRC = $(BOARD_PATH)/boards/GENERIC_STM32_F303XC/board.c + +# Required include directories +BOARDINC = $(BOARD_PATH)/boards/GENERIC_STM32_F303XC diff --git a/keyboards/_qmk_handwire/bootloader_defs.h b/keyboards/_qmk_handwire/bootloader_defs.h new file mode 100644 index 0000000000..3b0e9d20a6 --- /dev/null +++ b/keyboards/_qmk_handwire/bootloader_defs.h @@ -0,0 +1,7 @@ +/* Address for jumping to bootloader on STM32 chips. */ +/* It is chip dependent, the correct number can be looked up here: + * http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf + * This also requires a patch to chibios: + * /tmk_core/tool/chibios/ch-bootloader-jump.patch + */ +#define STM32_BOOTLOADER_ADDRESS 0x1FFFD800 diff --git a/keyboards/_qmk_handwire/chconf.h b/keyboards/_qmk_handwire/chconf.h new file mode 100644 index 0000000000..5a9b833107 --- /dev/null +++ b/keyboards/_qmk_handwire/chconf.h @@ -0,0 +1,520 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/chconf.h + * @brief Configuration file template. + * @details A copy of this file must be placed in each project directory, it + * contains the application specific kernel settings. + * + * @addtogroup config + * @details Kernel related settings and hooks. + * @{ + */ + +#ifndef CHCONF_H +#define CHCONF_H + +#define _CHIBIOS_RT_CONF_ + +/*===========================================================================*/ +/** + * @name System timers settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief System time counter resolution. + * @note Allowed values are 16 or 32 bits. + */ +#define CH_CFG_ST_RESOLUTION 32 + +/** + * @brief System tick frequency. + * @details Frequency of the system timer that drives the system ticks. This + * setting also defines the system tick time unit. + */ +#define CH_CFG_ST_FREQUENCY 10000 + +/** + * @brief Time delta constant for the tick-less mode. + * @note If this value is zero then the system uses the classic + * periodic tick. This value represents the minimum number + * of ticks that is safe to specify in a timeout directive. + * The value one is not valid, timeouts are rounded up to + * this value. + */ +#define CH_CFG_ST_TIMEDELTA 2 + +/** @} */ + +/*===========================================================================*/ +/** + * @name Kernel parameters and options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Round robin interval. + * @details This constant is the number of system ticks allowed for the + * threads before preemption occurs. Setting this value to zero + * disables the preemption for threads with equal priority and the + * round robin becomes cooperative. Note that higher priority + * threads can still preempt, the kernel is always preemptive. + * @note Disabling the round robin preemption makes the kernel more compact + * and generally faster. + * @note The round robin preemption is not supported in tickless mode and + * must be set to zero in that case. + */ +#define CH_CFG_TIME_QUANTUM 0 + +/** + * @brief Managed RAM size. + * @details Size of the RAM area to be managed by the OS. If set to zero + * then the whole available RAM is used. The core memory is made + * available to the heap allocator and/or can be used directly through + * the simplified core memory allocator. + * + * @note In order to let the OS manage the whole RAM the linker script must + * provide the @p __heap_base__ and @p __heap_end__ symbols. + * @note Requires @p CH_CFG_USE_MEMCORE. + */ +#define CH_CFG_MEMCORE_SIZE 0 + +/** + * @brief Idle thread automatic spawn suppression. + * @details When this option is activated the function @p chSysInit() + * does not spawn the idle thread. The application @p main() + * function becomes the idle thread and must implement an + * infinite loop. + */ +#define CH_CFG_NO_IDLE_THREAD FALSE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Performance options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief OS optimization. + * @details If enabled then time efficient rather than space efficient code + * is used when two possible implementations exist. + * + * @note This is not related to the compiler optimization options. + * @note The default is @p TRUE. + */ +#define CH_CFG_OPTIMIZE_SPEED TRUE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Subsystem options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Time Measurement APIs. + * @details If enabled then the time measurement APIs are included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_TM TRUE + +/** + * @brief Threads registry APIs. + * @details If enabled then the registry APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_REGISTRY TRUE + +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + +/** + * @brief Semaphores APIs. + * @details If enabled then the Semaphores APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_SEMAPHORES TRUE + +/** + * @brief Semaphores queuing mode. + * @details If enabled then the threads are enqueued on semaphores by + * priority rather than in FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special + * requirements. + * @note Requires @p CH_CFG_USE_SEMAPHORES. + */ +#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE + +/** + * @brief Mutexes APIs. + * @details If enabled then the mutexes APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MUTEXES TRUE + +/** + * @brief Enables recursive behavior on mutexes. + * @note Recursive mutexes are heavier and have an increased + * memory footprint. + * + * @note The default is @p FALSE. + * @note Requires @p CH_CFG_USE_MUTEXES. + */ +#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE + +/** + * @brief Conditional Variables APIs. + * @details If enabled then the conditional variables APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_MUTEXES. + */ +#define CH_CFG_USE_CONDVARS TRUE + +/** + * @brief Conditional Variables APIs with timeout. + * @details If enabled then the conditional variables APIs with timeout + * specification are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_CONDVARS. + */ +#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE + +/** + * @brief Events Flags APIs. + * @details If enabled then the event flags APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_EVENTS TRUE + +/** + * @brief Events Flags APIs with timeout. + * @details If enabled then the events APIs with timeout specification + * are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_EVENTS. + */ +#define CH_CFG_USE_EVENTS_TIMEOUT TRUE + +/** + * @brief Synchronous Messages APIs. + * @details If enabled then the synchronous messages APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MESSAGES TRUE + +/** + * @brief Synchronous Messages queuing mode. + * @details If enabled then messages are served by priority rather than in + * FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special + * requirements. + * @note Requires @p CH_CFG_USE_MESSAGES. + */ +#define CH_CFG_USE_MESSAGES_PRIORITY TRUE + +/** + * @brief Mailboxes APIs. + * @details If enabled then the asynchronous messages (mailboxes) APIs are + * included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_SEMAPHORES. + */ +#define CH_CFG_USE_MAILBOXES TRUE + +/** + * @brief Core Memory Manager APIs. + * @details If enabled then the core memory manager APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MEMCORE TRUE + +/** + * @brief Heap Allocator APIs. + * @details If enabled then the memory heap allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or + * @p CH_CFG_USE_SEMAPHORES. + * @note Mutexes are recommended. + */ +#define CH_CFG_USE_HEAP TRUE + +/** + * @brief Memory Pools Allocator APIs. + * @details If enabled then the memory pools allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MEMPOOLS TRUE + +/** + * @brief Dynamic Threads APIs. + * @details If enabled then the dynamic threads creation APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_WAITEXIT. + * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS. + */ +#define CH_CFG_USE_DYNAMIC TRUE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Debug options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Debug option, kernel statistics. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_STATISTICS FALSE + +/** + * @brief Debug option, system state check. + * @details If enabled the correct call protocol for system APIs is checked + * at runtime. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_SYSTEM_STATE_CHECK FALSE + +/** + * @brief Debug option, parameters checks. + * @details If enabled then the checks on the API functions input + * parameters are activated. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_ENABLE_CHECKS FALSE + +/** + * @brief Debug option, consistency checks. + * @details If enabled then all the assertions in the kernel code are + * activated. This includes consistency checks inside the kernel, + * runtime anomalies and port-defined checks. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_ENABLE_ASSERTS FALSE + +/** + * @brief Debug option, trace buffer. + * @details If enabled then the trace buffer is activated. + * + * @note The default is @p CH_DBG_TRACE_MASK_DISABLED. + */ +#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED + +/** + * @brief Trace buffer entries. + * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is + * different from @p CH_DBG_TRACE_MASK_DISABLED. + */ +#define CH_DBG_TRACE_BUFFER_SIZE 128 + +/** + * @brief Debug option, stack checks. + * @details If enabled then a runtime stack check is performed. + * + * @note The default is @p FALSE. + * @note The stack check is performed in a architecture/port dependent way. + * It may not be implemented or some ports. + * @note The default failure mode is to halt the system with the global + * @p panic_msg variable set to @p NULL. + */ +#define CH_DBG_ENABLE_STACK_CHECK TRUE + +/** + * @brief Debug option, stacks initialization. + * @details If enabled then the threads working area is filled with a byte + * value when a thread is created. This can be useful for the + * runtime measurement of the used stack. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_FILL_THREADS FALSE + +/** + * @brief Debug option, threads profiling. + * @details If enabled then a field is added to the @p thread_t structure that + * counts the system ticks occurred while executing the thread. + * + * @note The default is @p FALSE. + * @note This debug option is not currently compatible with the + * tickless mode. + */ +#define CH_DBG_THREADS_PROFILING FALSE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Kernel hooks + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Threads descriptor structure extension. + * @details User fields added to the end of the @p thread_t structure. + */ +#define CH_CFG_THREAD_EXTRA_FIELDS \ + /* Add threads custom fields here.*/ + +/** + * @brief Threads initialization hook. + * @details User initialization code added to the @p chThdInit() API. + * + * @note It is invoked from within @p chThdInit() and implicitly from all + * the threads creation APIs. + */ +#define CH_CFG_THREAD_INIT_HOOK(tp) { \ + /* Add threads initialization code here.*/ \ +} + +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) { \ + /* Add threads finalization code here.*/ \ +} + +/** + * @brief Context switch hook. + * @details This hook is invoked just before switching between threads. + */ +#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \ + /* Context switch code here.*/ \ +} + +/** + * @brief ISR enter hook. + */ +#define CH_CFG_IRQ_PROLOGUE_HOOK() { \ + /* IRQ prologue code here.*/ \ +} + +/** + * @brief ISR exit hook. + */ +#define CH_CFG_IRQ_EPILOGUE_HOOK() { \ + /* IRQ epilogue code here.*/ \ +} + +/** + * @brief Idle thread enter hook. + * @note This hook is invoked within a critical zone, no OS functions + * should be invoked from here. + * @note This macro can be used to activate a power saving mode. + */ +#define CH_CFG_IDLE_ENTER_HOOK() { \ + /* Idle-enter code here.*/ \ +} + +/** + * @brief Idle thread leave hook. + * @note This hook is invoked within a critical zone, no OS functions + * should be invoked from here. + * @note This macro can be used to deactivate a power saving mode. + */ +#define CH_CFG_IDLE_LEAVE_HOOK() { \ + /* Idle-leave code here.*/ \ +} + +/** + * @brief Idle Loop hook. + * @details This hook is continuously invoked by the idle thread loop. + */ +#define CH_CFG_IDLE_LOOP_HOOK() { \ + /* Idle loop code here.*/ \ +} + +/** + * @brief System tick event hook. + * @details This hook is invoked in the system tick handler immediately + * after processing the virtual timers queue. + */ +#define CH_CFG_SYSTEM_TICK_HOOK() { \ + /* System tick event code here.*/ \ +} + +/** + * @brief System halt hook. + * @details This hook is invoked in case to a system halting error before + * the system is halted. + */ +#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ + /* System halt code here.*/ \ +} + +/** + * @brief Trace hook. + * @details This hook is invoked each time a new record is written in the + * trace buffer. + */ +#define CH_CFG_TRACE_HOOK(tep) { \ + /* Trace code here.*/ \ +} + +/** @} */ + +/*===========================================================================*/ +/* Port-specific settings (override port settings defaulted in chcore.h). */ +/*===========================================================================*/ + +#endif /* CHCONF_H */ + +/** @} */ diff --git a/keyboards/_qmk_handwire/config.h b/keyboards/_qmk_handwire/config.h new file mode 100644 index 0000000000..0832fffc2a --- /dev/null +++ b/keyboards/_qmk_handwire/config.h @@ -0,0 +1,133 @@ +/* + * Copyright 2017 skully + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef CONFIG_H +#define CONFIG_H + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xC1ED +#define PRODUCT_ID 0x2350 +#define DEVICE_VER 0x0001 +#define MANUFACTURER "QMK" +#define USBSTR_MANUFACTURER 'Q', '\x00', 'M', '\x00', 'K', '\x00' +#define PRODUCT "Handwire" +#define USBSTR_PRODUCT 'H', '\x00', 'a', '\x00', 'n', '\x00', 'd', '\x00', 'w', '\x00', 'i', '\x00', 'r', '\x00', 'e', '\x00' +#define DESCRIPTION "Handwire protoboard" + +/* key matrix size */ +#define MATRIX_ROWS 5 +#define MATRIX_COLS 15 + +/* + * Keyboard Matrix Assignments + * + * Change this to how you wired your keyboard + * COLS: AVR pins used for columns, left to right + * ROWS: AVR pins used for rows, top to bottom + * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode) + * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) + * +*/ +/* Note: These are not used for arm boards. They're here purely as documentation. + * #define MATRIX_ROW_PINS { PB0, PB1, PB2, PA15, PA10 } + * #define MATRIX_COL_PINS { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 } + * #define UNUSED_PINS + */ + +/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ +#define DEBOUNCE 6 + +/* Prevent modifiers from being stuck on after layer changes. */ +#define PREVENT_STUCK_MODIFIERS + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +//#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +//#define LOCKING_RESYNC_ENABLE + +/* + * Force NKRO + * + * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved + * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the + * makefile for this to work.) + * + * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N) + * until the next keyboard reset. + * + * NKRO may prevent your keystrokes from being detected in the BIOS, but it is + * fully operational during normal computer usage. + * + * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N) + * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by + * bootmagic, NKRO mode will always be enabled until it is toggled again during a + * power-up. + * + */ +//#define FORCE_NKRO + +/* key combination for magic key command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +//#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 1 + +#endif + + /* Backlight configuration + */ +#define BACKLIGHT_LEVELS 1 diff --git a/keyboards/_qmk_handwire/halconf.h b/keyboards/_qmk_handwire/halconf.h new file mode 100644 index 0000000000..254470cbd0 --- /dev/null +++ b/keyboards/_qmk_handwire/halconf.h @@ -0,0 +1,388 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/halconf.h + * @brief HAL configuration header. + * @details HAL configuration file, this file allows to enable or disable the + * various device drivers from your application. You may also use + * this file in order to override the device drivers default settings. + * + * @addtogroup HAL_CONF + * @{ + */ + +#ifndef HALCONF_H +#define HALCONF_H + +#include "mcuconf.h" + +/** + * @brief Enables the PAL subsystem. + */ +#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__) +#define HAL_USE_PAL TRUE +#endif + +/** + * @brief Enables the ADC subsystem. + */ +#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) +#define HAL_USE_ADC FALSE +#endif + +/** + * @brief Enables the CAN subsystem. + */ +#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__) +#define HAL_USE_CAN FALSE +#endif + +/** + * @brief Enables the DAC subsystem. + */ +#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__) +#define HAL_USE_DAC TRUE +#endif + +/** + * @brief Enables the EXT subsystem. + */ +#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__) +#define HAL_USE_EXT FALSE +#endif + +/** + * @brief Enables the GPT subsystem. + */ +#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__) +#define HAL_USE_GPT TRUE +#endif + +/** + * @brief Enables the I2C subsystem. + */ +#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) +#define HAL_USE_I2C FALSE +#endif + +/** + * @brief Enables the I2S subsystem. + */ +#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__) +#define HAL_USE_I2S FALSE +#endif + +/** + * @brief Enables the ICU subsystem. + */ +#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__) +#define HAL_USE_ICU FALSE +#endif + +/** + * @brief Enables the MAC subsystem. + */ +#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__) +#define HAL_USE_MAC FALSE +#endif + +/** + * @brief Enables the MMC_SPI subsystem. + */ +#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__) +#define HAL_USE_MMC_SPI FALSE +#endif + +/** + * @brief Enables the PWM subsystem. + */ +#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) +#define HAL_USE_PWM FALSE +#endif + +/** + * @brief Enables the QSPI subsystem. + */ +#if !defined(HAL_USE_QSPI) || defined(__DOXYGEN__) +#define HAL_USE_QSPI FALSE +#endif + +/** + * @brief Enables the RTC subsystem. + */ +#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +#define HAL_USE_RTC FALSE +#endif + +/** + * @brief Enables the SDC subsystem. + */ +#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__) +#define HAL_USE_SDC FALSE +#endif + +/** + * @brief Enables the SERIAL subsystem. + */ +#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL FALSE +#endif + +/** + * @brief Enables the SERIAL over USB subsystem. + */ +#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL_USB TRUE +#endif + +/** + * @brief Enables the SPI subsystem. + */ +#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__) +#define HAL_USE_SPI FALSE +#endif + +/** + * @brief Enables the UART subsystem. + */ +#if !defined(HAL_USE_UART) || defined(__DOXYGEN__) +#define HAL_USE_UART FALSE +#endif + +/** + * @brief Enables the USB subsystem. + */ +#if !defined(HAL_USE_USB) || defined(__DOXYGEN__) +#define HAL_USE_USB TRUE +#endif + +/** + * @brief Enables the WDG subsystem. + */ +#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__) +#define HAL_USE_WDG FALSE +#endif + +/*===========================================================================*/ +/* ADC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__) +#define ADC_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define ADC_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* CAN driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Sleep mode related APIs inclusion switch. + */ +#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__) +#define CAN_USE_SLEEP_MODE TRUE +#endif + +/*===========================================================================*/ +/* I2C driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables the mutual exclusion APIs on the I2C bus. + */ +#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define I2C_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* MAC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__) +#define MAC_USE_ZERO_COPY FALSE +#endif + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__) +#define MAC_USE_EVENTS TRUE +#endif + +/*===========================================================================*/ +/* MMC_SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + * This option is recommended also if the SPI driver does not + * use a DMA channel and heavily loads the CPU. + */ +#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__) +#define MMC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SDC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Number of initialization attempts before rejecting the card. + * @note Attempts are performed at 10mS intervals. + */ +#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__) +#define SDC_INIT_RETRY 100 +#endif + +/** + * @brief Include support for MMC cards. + * @note MMC support is not yet implemented so this option must be kept + * at @p FALSE. + */ +#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__) +#define SDC_MMC_SUPPORT FALSE +#endif + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + */ +#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__) +#define SDC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SERIAL driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Default bit rate. + * @details Configuration parameter, this is the baud rate selected for the + * default configuration. + */ +#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__) +#define SERIAL_DEFAULT_BITRATE 38400 +#endif + +/** + * @brief Serial buffers size. + * @details Configuration parameter, you can change the depth of the queue + * buffers depending on the requirements of your application. + * @note The default is 16 bytes for both the transmission and receive + * buffers. + */ +#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define SERIAL_BUFFERS_SIZE 16 +#endif + +/*===========================================================================*/ +/* SERIAL_USB driver related setting. */ +/*===========================================================================*/ + +/** + * @brief Serial over USB buffers size. + * @details Configuration parameter, the buffer size must be a multiple of + * the USB data endpoint maximum packet size. + * @note The default is 256 bytes for both the transmission and receive + * buffers. + */ +#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define SERIAL_USB_BUFFERS_SIZE 256 +#endif + +/** + * @brief Serial over USB number of buffers. + * @note The default is 2 buffers. + */ +#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__) +#define SERIAL_USB_BUFFERS_NUMBER 2 +#endif + +/*===========================================================================*/ +/* SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__) +#define SPI_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define SPI_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* UART driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__) +#define UART_USE_WAIT FALSE +#endif + +/** + * @brief Enables the @p uartAcquireBus() and @p uartReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define UART_USE_MUTUAL_EXCLUSION FALSE +#endif + +/*===========================================================================*/ +/* USB driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__) +#define USB_USE_WAIT TRUE +#endif + +#endif /* HALCONF_H */ + +/** @} */ diff --git a/keyboards/_qmk_handwire/keymaps/default/keymap.c b/keyboards/_qmk_handwire/keymaps/default/keymap.c new file mode 100644 index 0000000000..96b507877d --- /dev/null +++ b/keyboards/_qmk_handwire/keymaps/default/keymap.c @@ -0,0 +1,127 @@ +#include "_qmk_handwire.h" + +#define _______ KC_TRNS + +enum keyboard_layers { + _BL, + _FL, + _CL +}; + +enum custom_keycodes { + S_BSKTC = SAFE_RANGE, + S_ODEJY, + S_RCKBY, + S_DOEDR, + S_SCALE, + S_ONEUP, + S_COIN, + S_SONIC, + S_ZELDA +}; + +#ifdef AUDIO_ENABLE + float song_basketcase[][2] = SONG(BASKET_CASE); + float song_ode_to_joy[][2] = SONG(ODE_TO_JOY); + float song_rock_a_bye_baby[][2] = SONG(ROCK_A_BYE_BABY); + float song_doe_a_deer[][2] = SONG(DOE_A_DEER); + float song_scale[][2] = SONG(MUSIC_SCALE_SOUND); + float song_coin[][2] = SONG(COIN_SOUND); + float song_one_up[][2] = SONG(ONE_UP_SOUND); + float song_sonic_ring[][2] = SONG(SONIC_RING); + float song_zelda_puzzle[][2] = SONG(ZELDA_PUZZLE); +#endif + +const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* Layer 0: Default Layer + * ,-----------------------------------------------------------. + * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| `|BSp| + * |-----------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| + * |-----------------------------------------------------------| + * |Contro| A| S| D| F| G| H| J| K| L| ;| '|Enter | + * |-----------------------------------------------------------| + * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn0| + * |-----------------------------------------------------------' + * |Ctrl |Gui|Alt | Space |Alt |Gui|Fn |Ctrl | + * `-----------------------------------------------------------' + */ + [_BL] = KEYMAP( + KC_GESC,KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_GRV, KC_BSPC,\ + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, \ + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,KC_NUHS, KC_ENT, \ + KC_LSFT, KC_NUBS,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, KC_BSLS, \ + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI, MO(_FL), KC_RCTL), + [_FL] = KEYMAP( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,_______,\ + _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, \ + _______, _______,MO(_CL),_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \ + _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______, \ + _______,_______,_______, _______, _______, _______, MO(_FL), _______), + [_CL] = KEYMAP( + BL_STEP,S_BSKTC,S_ODEJY,S_RCKBY,S_DOEDR,S_SCALE,S_ONEUP,S_COIN, S_SONIC,S_ZELDA,_______,_______,_______,_______,_______,\ + _______, _______,_______,_______,RESET, _______,_______,_______,_______,_______,_______,_______,_______,_______, \ + _______, _______,MO(_CL),_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \ + _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \ + _______, _______, _______, _______, _______, _______, MO(_FL), _______) +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case S_BSKTC: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_basketcase); + } + return false; + case S_ODEJY: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_ode_to_joy); + } + return false; + case S_RCKBY: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_rock_a_bye_baby); + } + return false; + case S_DOEDR: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_doe_a_deer); + } + return false; + case S_SCALE: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_scale); + } + return false; + case S_ONEUP: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_one_up); + } + return false; + case S_COIN: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_coin); + } + return false; + case S_SONIC: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_sonic_ring); + } + return false; + case S_ZELDA: + if (record->event.pressed) { + stop_all_notes(); + PLAY_SONG(song_zelda_puzzle); + } + return false; + } + return true; +} diff --git a/keyboards/_qmk_handwire/keymaps/default/readme.md b/keyboards/_qmk_handwire/keymaps/default/readme.md new file mode 100644 index 0000000000..32d4bfba61 --- /dev/null +++ b/keyboards/_qmk_handwire/keymaps/default/readme.md @@ -0,0 +1 @@ +# The default keymap for clueboard 60% diff --git a/keyboards/_qmk_handwire/led.c b/keyboards/_qmk_handwire/led.c new file mode 100644 index 0000000000..350696736b --- /dev/null +++ b/keyboards/_qmk_handwire/led.c @@ -0,0 +1,53 @@ +/* + * Copyright 2017 skully + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +#include "hal.h" +#include "backlight.h" +#include "led.h" +#include "printf.h" + +void backlight_init_ports(void) { + printf("backlight_init_ports()\n"); + #ifdef BACKLIGHT_ENABLE + palSetPadMode(GPIOB, 8, PAL_MODE_OUTPUT_PUSHPULL); + palSetPad(GPIOB, 8); + #endif +} + +void backlight_set(uint8_t level) { + printf("backlight_set(%d)\n", level); + #ifdef BACKLIGHT_ENABLE + if (level == 0) { + // Turn backlight off + palSetPad(GPIOB, 8); + } else { + // Turn backlight on + palClearPad(GPIOB, 8); + } + #endif +} + +void led_set_kb(uint8_t usb_led) { + printf("led_set_kb(%d)\n", usb_led); + if (usb_led & (1< +#include +#include +#include "hal.h" +#include "timer.h" +#include "wait.h" +#include "printf.h" +#include "backlight.h" +#include "matrix.h" + + +/* QMK Handwire + * + * Column pins are input with internal pull-down. + * Row pins are output and strobe with high. + * Key is high or 1 when it turns on. + * + * col: { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC15, PC14, PC13, PB5, PB6 } + * row: { PB0, PB1, PB2, PA15, PA10 } + */ +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_COLS]; +static bool debouncing = false; +static uint16_t debouncing_time = 0; + +__attribute__ ((weak)) +void matrix_init_user(void) {} + +__attribute__ ((weak)) +void matrix_scan_user(void) {} + +__attribute__ ((weak)) +void matrix_init_kb(void) { + matrix_init_user(); +} + +__attribute__ ((weak)) +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +void matrix_init(void) { + printf("matrix init\n"); + //debug_matrix = true; + + /* Column(sense) */ + palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 14, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 15, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 8, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 9, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 4, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 15, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 14, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 6, PAL_MODE_OUTPUT_PUSHPULL); + + /* Row(strobe) */ + palSetPadMode(GPIOB, 0, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOB, 1, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOB, 2, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLDOWN); + + memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t)); + memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t)); + + palClearPad(GPIOB, 7); // Turn off capslock + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) { + for (int col = 0; col < MATRIX_COLS; col++) { + matrix_row_t data = 0; + + // strobe col { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 } + switch (col) { + case 0: palSetPad(GPIOA, 2); break; + case 1: palSetPad(GPIOA, 3); break; + case 2: palSetPad(GPIOA, 6); break; + case 3: palSetPad(GPIOB, 14); break; + case 4: palSetPad(GPIOB, 15); break; + case 5: palSetPad(GPIOA, 8); break; + case 6: palSetPad(GPIOA, 9); break; + case 7: palSetPad(GPIOA, 7); break; + case 8: palSetPad(GPIOB, 3); break; + case 9: palSetPad(GPIOB, 4); break; + case 10: palSetPad(GPIOC, 15); break; + case 11: palSetPad(GPIOC, 14); break; + case 12: palSetPad(GPIOC, 13); break; + case 13: palSetPad(GPIOB, 5); break; + case 14: palSetPad(GPIOB, 6); break; + } + + // need wait to settle pin state + wait_us(20); + + // read row data { PB0, PB1, PB2, PA15, PA10 } + data = ( + (palReadPad(GPIOB, 0) << 0 ) | + (palReadPad(GPIOB, 1) << 1 ) | + (palReadPad(GPIOB, 2) << 2 ) | + (palReadPad(GPIOA, 15) << 3 ) | + (palReadPad(GPIOA, 10) << 4 ) + ); + + // unstrobe col { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC15, PC14, PC13, PB5, PB6 } + switch (col) { + case 0: palClearPad(GPIOA, 2); break; + case 1: palClearPad(GPIOA, 3); break; + case 2: palClearPad(GPIOA, 6); break; + case 3: palClearPad(GPIOB, 14); break; + case 4: palClearPad(GPIOB, 15); break; + case 5: palClearPad(GPIOA, 8); break; + case 6: palClearPad(GPIOA, 9); break; + case 7: palClearPad(GPIOA, 7); break; + case 8: palClearPad(GPIOB, 3); break; + case 9: palClearPad(GPIOB, 4); break; + case 10: palClearPad(GPIOC, 15); break; + case 11: palClearPad(GPIOC, 14); break; + case 12: palClearPad(GPIOC, 13); break; + case 13: palClearPad(GPIOB, 5); break; + case 14: palClearPad(GPIOB, 6); break; + } + + if (matrix_debouncing[col] != data) { + matrix_debouncing[col] = data; + debouncing = true; + debouncing_time = timer_read(); + } + } + + if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { + for (int row = 0; row < MATRIX_ROWS; row++) { + matrix[row] = 0; + for (int col = 0; col < MATRIX_COLS; col++) { + matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col); + } + } + debouncing = false; + } + + matrix_scan_quantum(); + + return 1; +} + +bool matrix_is_on(uint8_t row, uint8_t col) { + return (matrix[row] & (1</os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) +MCU_FAMILY = STM32 +MCU_SERIES = STM32F3xx + +# Linker script to use +# - it should exist either in /os/common/ports/ARMCMx/compilers/GCC/ld/ +# or /ld/ +MCU_LDSCRIPT = STM32F303xC + +# Startup code to use +# - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ +MCU_STARTUP = stm32f3xx + +# Board: it should exist either in /os/hal/boards/ +# or /boards +BOARD = GENERIC_STM32_F303XC + +# Cortex version +MCU = cortex-m4 + +# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7 +ARMV = 7 + +USE_FPU = yes + +# Vector table for application +# 0x00000000-0x00001000 area is occupied by bootlaoder.*/ +# The CORTEX_VTOR... is needed only for MCHCK/Infinity KB +# OPT_DEFS = -DCORTEX_VTOR_INIT=0x08005000 +OPT_DEFS = + +# Options to pass to dfu-util when flashing +DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000 -R + +# Build Options +# comment out to disable the options. +# +BACKLIGHT_ENABLE = no +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration +## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.) +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = yes # Commands for debug and configuration +#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +NKRO_ENABLE = yes # USB Nkey Rollover +CUSTOM_MATRIX = yes # Custom matrix file +AUDIO_ENABLE = yes +# SERIAL_LINK_ENABLE = yes From fc91bf4a659d3cdfc0712b2aa7dcadb32674ca6d Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 1 Feb 2018 14:48:25 -0500 Subject: [PATCH 05/42] updated matrix and keymap --- keyboards/_qmk_handwire/_qmk_handwire.h | 22 ++-- keyboards/_qmk_handwire/config.h | 8 +- keyboards/_qmk_handwire/halconf.h | 2 +- .../_qmk_handwire/keymaps/default/keymap.c | 39 ++---- keyboards/_qmk_handwire/led.c | 12 +- keyboards/_qmk_handwire/matrix.c | 119 +++++++----------- keyboards/_qmk_handwire/mcuconf.h | 2 +- keyboards/_qmk_handwire/rules.mk | 2 +- 8 files changed, 79 insertions(+), 127 deletions(-) diff --git a/keyboards/_qmk_handwire/_qmk_handwire.h b/keyboards/_qmk_handwire/_qmk_handwire.h index 886b92016a..e16ae3ba9b 100644 --- a/keyboards/_qmk_handwire/_qmk_handwire.h +++ b/keyboards/_qmk_handwire/_qmk_handwire.h @@ -29,17 +29,19 @@ /* The fully-featured KEYMAP() that has every single key available in the matrix. */ #define KEYMAP(\ - k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, k0c, k0d, k0e, \ - k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1e, \ - k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2e, \ - k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3e, \ - k40, k41, k42, k47, k4a, k4b, k4c, k4e \ + k00, k01, k02, k03, k04, k05, k06, \ + k10, k11, k12, k13, k14, k15, k16, \ + k20, k21, k22, k23, k24, k25, k26, \ + k31, k32, k33, k34, k35, k36, \ + k42, k43, k44, k45, k46, \ + k50, k51, k52 \ ) { \ - { k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, k0c, k0d, k0e, }, \ - { k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, KC_NO, k1e, }, \ - { k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, KC_NO, k2e, }, \ - { k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, KC_NO, k3e, }, \ - { k40, k41, k42, KC_NO, KC_NO, KC_NO, KC_NO, k47, KC_NO, KC_NO, k4a, k4b, k4c, KC_NO, k4e, }, \ + { k00, k01, k02, k03, k04, k05, k06 }, \ + { k10, k11, k12, k13, k14, k15, k16 }, \ + { k20, k21, k22, k23, k24, k25, k26 }, \ + { 0, k31, k32, k33, k34, k35, k36 }, \ + { 0, 0, k42, k43, k44, k45, k46 }, \ + { k50, k51, k52, 0, 0, 0, 0 } \ } #endif \ No newline at end of file diff --git a/keyboards/_qmk_handwire/config.h b/keyboards/_qmk_handwire/config.h index 0832fffc2a..70930b25f6 100644 --- a/keyboards/_qmk_handwire/config.h +++ b/keyboards/_qmk_handwire/config.h @@ -19,8 +19,8 @@ #define CONFIG_H /* USB Device descriptor parameter */ -#define VENDOR_ID 0xC1ED -#define PRODUCT_ID 0x2350 +#define VENDOR_ID 0x125A +#define PRODUCT_ID 0x1770 #define DEVICE_VER 0x0001 #define MANUFACTURER "QMK" #define USBSTR_MANUFACTURER 'Q', '\x00', 'M', '\x00', 'K', '\x00' @@ -29,8 +29,8 @@ #define DESCRIPTION "Handwire protoboard" /* key matrix size */ -#define MATRIX_ROWS 5 -#define MATRIX_COLS 15 +#define MATRIX_ROWS 6 +#define MATRIX_COLS 7 /* * Keyboard Matrix Assignments diff --git a/keyboards/_qmk_handwire/halconf.h b/keyboards/_qmk_handwire/halconf.h index 254470cbd0..d2a7653f5d 100644 --- a/keyboards/_qmk_handwire/halconf.h +++ b/keyboards/_qmk_handwire/halconf.h @@ -76,7 +76,7 @@ * @brief Enables the I2C subsystem. */ #if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) -#define HAL_USE_I2C FALSE +#define HAL_USE_I2C TRUE #endif /** diff --git a/keyboards/_qmk_handwire/keymaps/default/keymap.c b/keyboards/_qmk_handwire/keymaps/default/keymap.c index 96b507877d..01af53408c 100644 --- a/keyboards/_qmk_handwire/keymaps/default/keymap.c +++ b/keyboards/_qmk_handwire/keymaps/default/keymap.c @@ -33,37 +33,14 @@ enum custom_keycodes { #endif const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - /* Layer 0: Default Layer - * ,-----------------------------------------------------------. - * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| `|BSp| - * |-----------------------------------------------------------| - * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| - * |-----------------------------------------------------------| - * |Contro| A| S| D| F| G| H| J| K| L| ;| '|Enter | - * |-----------------------------------------------------------| - * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn0| - * |-----------------------------------------------------------' - * |Ctrl |Gui|Alt | Space |Alt |Gui|Fn |Ctrl | - * `-----------------------------------------------------------' - */ - [_BL] = KEYMAP( - KC_GESC,KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_GRV, KC_BSPC,\ - KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, \ - KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,KC_NUHS, KC_ENT, \ - KC_LSFT, KC_NUBS,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, KC_BSLS, \ - KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI, MO(_FL), KC_RCTL), - [_FL] = KEYMAP( - KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,_______,\ - _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, \ - _______, _______,MO(_CL),_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \ - _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, _______, \ - _______,_______,_______, _______, _______, _______, MO(_FL), _______), - [_CL] = KEYMAP( - BL_STEP,S_BSKTC,S_ODEJY,S_RCKBY,S_DOEDR,S_SCALE,S_ONEUP,S_COIN, S_SONIC,S_ZELDA,_______,_______,_______,_______,_______,\ - _______, _______,_______,_______,RESET, _______,_______,_______,_______,_______,_______,_______,_______,_______, \ - _______, _______,MO(_CL),_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \ - _______, _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, \ - _______, _______, _______, _______, _______, _______, MO(_FL), _______) + [0] = KEYMAP( + KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, + KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, + KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, + KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, + MO(2), MO(1), KC_SPC + ) }; bool process_record_user(uint16_t keycode, keyrecord_t *record) { diff --git a/keyboards/_qmk_handwire/led.c b/keyboards/_qmk_handwire/led.c index 350696736b..42cbe0d4d9 100644 --- a/keyboards/_qmk_handwire/led.c +++ b/keyboards/_qmk_handwire/led.c @@ -23,8 +23,8 @@ void backlight_init_ports(void) { printf("backlight_init_ports()\n"); #ifdef BACKLIGHT_ENABLE - palSetPadMode(GPIOB, 8, PAL_MODE_OUTPUT_PUSHPULL); - palSetPad(GPIOB, 8); + // palSetPadMode(GPIOB, 8, PAL_MODE_OUTPUT_PUSHPULL); + // palSetPad(GPIOB, 8); #endif } @@ -33,10 +33,10 @@ void backlight_set(uint8_t level) { #ifdef BACKLIGHT_ENABLE if (level == 0) { // Turn backlight off - palSetPad(GPIOB, 8); + // palSetPad(GPIOB, 8); } else { // Turn backlight on - palClearPad(GPIOB, 8); + // palClearPad(GPIOB, 8); } #endif } @@ -45,9 +45,9 @@ void led_set_kb(uint8_t usb_led) { printf("led_set_kb(%d)\n", usb_led); if (usb_led & (1< DEBOUNCE) { for (int row = 0; row < MATRIX_ROWS; row++) { - matrix[row] = 0; - for (int col = 0; col < MATRIX_COLS; col++) { - matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col); - } + matrix[row] = matrix_debouncing[row]; } debouncing = false; } - matrix_scan_quantum(); return 1; diff --git a/keyboards/_qmk_handwire/mcuconf.h b/keyboards/_qmk_handwire/mcuconf.h index 94cb540ec9..226da48d59 100644 --- a/keyboards/_qmk_handwire/mcuconf.h +++ b/keyboards/_qmk_handwire/mcuconf.h @@ -154,7 +154,7 @@ /* * I2C driver system settings. */ -#define STM32_I2C_USE_I2C1 FALSE +#define STM32_I2C_USE_I2C1 TRUE #define STM32_I2C_USE_I2C2 FALSE #define STM32_I2C_BUSY_TIMEOUT 50 #define STM32_I2C_I2C1_IRQ_PRIORITY 10 diff --git a/keyboards/_qmk_handwire/rules.mk b/keyboards/_qmk_handwire/rules.mk index 2def050b2b..acabc0f950 100644 --- a/keyboards/_qmk_handwire/rules.mk +++ b/keyboards/_qmk_handwire/rules.mk @@ -36,7 +36,7 @@ USE_FPU = yes OPT_DEFS = # Options to pass to dfu-util when flashing -DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000 -R +DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000:leave # Build Options # comment out to disable the options. From fae437cfadcd393009e148442e48c046c126a5b0 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 7 Feb 2018 17:17:39 -0500 Subject: [PATCH 06/42] update matrix --- drivers/arm/twi2c.c | 33 +++++++++++++++++++ drivers/arm/twi2c.h | 18 ++++++++++ keyboards/_qmk_handwire/_qmk_handwire.h | 12 +++++++ keyboards/_qmk_handwire/config.h | 2 +- .../_qmk_handwire/keymaps/default/keymap.c | 7 ++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 drivers/arm/twi2c.c create mode 100644 drivers/arm/twi2c.h diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c new file mode 100644 index 0000000000..e6cab25b50 --- /dev/null +++ b/drivers/arm/twi2c.c @@ -0,0 +1,33 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "twi2c.h" + +#ifndef I2C_DRIVER + #define I2C_DRIVER &I2CD1 +#endif + +static const I2CConfig i2cconfig = { + STM32_TIMINGR_PRESC(15U) | + STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) | + STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U), + 0, + 0 +}; + +void twi2c_init(void) { + i2cStart(I2C_DRIVER, &i2cconfig); +} \ No newline at end of file diff --git a/drivers/arm/twi2c.h b/drivers/arm/twi2c.h new file mode 100644 index 0000000000..a1847d436d --- /dev/null +++ b/drivers/arm/twi2c.h @@ -0,0 +1,18 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ch.h" +#include "hal.h" \ No newline at end of file diff --git a/keyboards/_qmk_handwire/_qmk_handwire.h b/keyboards/_qmk_handwire/_qmk_handwire.h index e16ae3ba9b..f482861f9a 100644 --- a/keyboards/_qmk_handwire/_qmk_handwire.h +++ b/keyboards/_qmk_handwire/_qmk_handwire.h @@ -29,6 +29,12 @@ /* The fully-featured KEYMAP() that has every single key available in the matrix. */ #define KEYMAP(\ + j00, j01, j02, j03, j04, j05, j06, \ + j10, j11, j12, j13, j14, j15, j16, \ + j20, j21, j22, j23, j24, j25, j26, \ + j30, j31, j32, j33, j34, j35, \ + j40, j41, j42, j43, j44, \ + j54, j55, j56, \ k00, k01, k02, k03, k04, k05, k06, \ k10, k11, k12, k13, k14, k15, k16, \ k20, k21, k22, k23, k24, k25, k26, \ @@ -36,6 +42,12 @@ k42, k43, k44, k45, k46, \ k50, k51, k52 \ ) { \ + { j00, j01, j02, j03, j04, j05, j06 }, \ + { j10, j11, j12, j13, j14, j15, j16 }, \ + { j20, j21, j22, j23, j24, j25, j26 }, \ + { j30, j31, j32, j33, j34, j35, 0 }, \ + { j40, j41, j42, j43, j44, 0, 0 }, \ + { 0, 0, 0, 0, j54, j55, j56 }, \ { k00, k01, k02, k03, k04, k05, k06 }, \ { k10, k11, k12, k13, k14, k15, k16 }, \ { k20, k21, k22, k23, k24, k25, k26 }, \ diff --git a/keyboards/_qmk_handwire/config.h b/keyboards/_qmk_handwire/config.h index 70930b25f6..6b3042ce01 100644 --- a/keyboards/_qmk_handwire/config.h +++ b/keyboards/_qmk_handwire/config.h @@ -29,7 +29,7 @@ #define DESCRIPTION "Handwire protoboard" /* key matrix size */ -#define MATRIX_ROWS 6 +#define MATRIX_ROWS 12 #define MATRIX_COLS 7 /* diff --git a/keyboards/_qmk_handwire/keymaps/default/keymap.c b/keyboards/_qmk_handwire/keymaps/default/keymap.c index 01af53408c..8469b6c395 100644 --- a/keyboards/_qmk_handwire/keymaps/default/keymap.c +++ b/keyboards/_qmk_handwire/keymaps/default/keymap.c @@ -34,6 +34,13 @@ enum custom_keycodes { const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = KEYMAP( + KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, + KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, + KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, + KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, + MO(2), MO(1), KC_SPC, + KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, From be81cd8c98315fc3b90ce1cf049b533eafecb88a Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 10 Feb 2018 16:32:05 -0500 Subject: [PATCH 07/42] adds i2c slave implementation --- common_features.mk | 11 + drivers/arm/twi2c.c | 196 +++++++++++++++++- .../boards/GENERIC_STM32_F303XC/board.h | 4 +- keyboards/_qmk_handwire/config.h | 7 +- keyboards/_qmk_handwire/halconf.h | 7 + .../_qmk_handwire/keymaps/default/keymap.c | 22 +- keyboards/_qmk_handwire/matrix.c | 94 ++++++--- keyboards/_qmk_handwire/rules.mk | 1 + lib/chibios | 2 +- tmk_core/avr.mk | 14 +- tmk_core/protocol/chibios/main.c | 5 +- 11 files changed, 300 insertions(+), 63 deletions(-) diff --git a/common_features.mk b/common_features.mk index 1c0b3546a1..8dfa64f9e8 100644 --- a/common_features.mk +++ b/common_features.mk @@ -20,6 +20,12 @@ SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) SERIAL_DEFS += -DSERIAL_LINK_ENABLE COMMON_VPATH += $(SERIAL_PATH) +ifeq ($(PLATFORM),AVR) + COMMON_VPATH += $(DRIVER_PATH)/avr +else + COMMON_VPATH += $(DRIVER_PATH)/arm +endif + ifeq ($(strip $(API_SYSEX_ENABLE)), yes) OPT_DEFS += -DAPI_SYSEX_ENABLE SRC += $(QUANTUM_DIR)/api/api_sysex.c @@ -184,6 +190,11 @@ ifeq ($(strip $(USB_HID_ENABLE)), yes) include $(TMK_DIR)/protocol/usb_hid.mk endif +ifeq ($(strip $(I2C_SLAVE_ENABLE)), yes) + SRC += twi2c.c + OPT_DEFS += -DI2C_SLAVE_ENABLE +endif + QUANTUM_SRC:= \ $(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/keymap_common.c \ diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index e6cab25b50..b6dc2d27ed 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -15,19 +15,203 @@ */ #include "twi2c.h" +#include +#include +#include "hal_i2cslave.h" +#include "chprintf.h" +#include "memstreams.h" +#include "printf.h" #ifndef I2C_DRIVER - #define I2C_DRIVER &I2CD1 + #define I2C_DRIVER I2CD1 #endif -static const I2CConfig i2cconfig = { +/** + * I2C slave test routine. + * + * To use: Add file to a project, call startComms() with the address of a serial stream + * + * There are two different responses: + * a) A read-only transaction - returns the "Initial Reply" message + * b) A write then read transaction - calls a message processor and returns the generated reply. + * Stretches clock until reply available. + */ + + +#define slaveI2Caddress 0x30 /* Address in our terms - halved by later code */ +//#define myOtherI2Caddress 0x19 + +I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; + +static const I2CConfig slaveI2Cconfig = { STM32_TIMINGR_PRESC(15U) | STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) | STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U), 0, - 0 + 0, + NULL }; -void twi2c_init(void) { - i2cStart(I2C_DRIVER, &i2cconfig); -} \ No newline at end of file +char initialReplyBody[50] = "Initial reply"; // 'Status' response if read without preceding write + + +uint32_t messageCounter = 0; /* Counts number of messages received to return as part of response */ + +uint8_t rxBody[240]; /* stores last message master sent us (intentionally a few bytes smaller than txBody) */ +uint8_t txBody[256]; /* Return message buffer for computed replies */ + +BaseSequentialStream *chp = NULL; // Used for serial logging + +// Handler when something sent to us +const I2CSlaveMsg echoRx = +{ + sizeof(rxBody), /* max sizeof received msg body */ + rxBody, /* body of received msg */ + NULL, /* do nothing on address match */ + twi2c_slave_message_process, /* Routine to process received messages */ + catchError /* Error hook */ +}; + + +// 'Empty' reply when nothing to say, and no message received. In RAM, to allow update +I2CSlaveMsg initialReply = +{ + sizeof(initialReplyBody), /* trailing zero byte will be repeated as needed */ + (uint8_t *)initialReplyBody, + NULL, /* do nothing on address match */ + NULL, /* do nothing after reply sent */ + catchError /* Error hook */ +}; + + +// Response to received messages +I2CSlaveMsg echoReply = { /* this is in RAM so size may be updated */ + 0, /* filled in with the length of the message to send */ + txBody, /* Response message */ + NULL, /* do nothing special on address match */ + clearAfterSend, /* Clear receive buffer once replied */ + catchError /* Error hook */ +}; + + +/** + * Track I2C errors + */ +uint8_t gotI2cError = 0; +uint32_t lastI2cErrorFlags = 0; + +// Called from ISR to log error +void noteI2cError(uint32_t flags) +{ + lastI2cErrorFlags = flags; + gotI2cError = 1; +} + + + +/** + * Generic error handler + * + * Called in interrupt context, so need to watch what we do + */ +void catchError(I2CDriver *i2cp) +{ + noteI2cError(i2cp->errors); +} + + + +const char hexString[16] = "0123456789abcdef"; + + +/** + * Message processor - looks at received message, determines reply as quickly as possible + * + * Responds with the value of the messageCounter (in hex), followed by the received message in [..] + * + * Note: Called in interrupt context, so need to be quick! + */ +void twi2c_slave_message_process(I2CDriver *i2cp) { + uint8_t i; + uint8_t *txPtr = txBody + 8; + uint8_t txLen; + uint32_t curCount; + + size_t len = i2cSlaveBytes(i2cp); // Number of bytes received + if (len >= sizeof(rxBody)) + len = sizeof(rxBody)-1; + rxBody[len]=0; // String termination sometimes useful + + /* A real-world application would read and decode the message in rxBody, then generate an appropriate reply in txBody */ + + curCount = ++messageCounter; + txLen = len + 11; // Add in the overhead + + for (i = 0; i < 8; i++) + { + *--txPtr = hexString[curCount & 0xf]; + curCount = curCount >> 4; + } + + txPtr = txBody + 8; + *txPtr++ = ' '; + *txPtr++ = '['; + memcpy(txPtr, rxBody, len); // Echo received message + txPtr += len; + *txPtr++ = ']'; + *txPtr = '\0'; + + /** Message ready to go here */ + echoReply.size = txLen; + i2cSlaveReplyI(i2cp, &echoReply); +} + + +/** + * Callback after sending of response complete - restores default reply in case polled + */ +void clearAfterSend(I2CDriver *i2cp) +{ + echoReply.size = 0; // Clear receive message + i2cSlaveReplyI(i2cp, &initialReply); +} + + +/** + * Start the I2C Slave port to accept comms from master CPU + * + * We then go into a loop checking for errors, and never return + */ + +void twi2c_slave_init(void) { + + palSetGroupMode(GPIOB,8,9, PAL_MODE_INPUT); // Try releasing special pins for a short time + chThdSleepMilliseconds(10); + + /* I2C1 SCL on PF1, SDA on PF0 */ + palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + + + i2cStart(&I2C_DRIVER, &slaveI2Cconfig); +#if HAL_USE_I2C_SLAVE + I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message +#endif + + i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply); + + // Enable match address after everything else set up + i2cMatchAddress(&I2C_DRIVER, slaveI2Caddress/2); +// i2cMatchAddress(&I2C_DRIVER, myOtherI2Caddress/2); +// i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */ + + printf("Slave I2C started\n\r"); + +} + +void twi2c_slave_task(void) { + if (gotI2cError) { + gotI2cError = 0; + printf("I2cError: %04x\r\n", lastI2cErrorFlags); + } +} diff --git a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h index 7405c0ea90..254c84a097 100644 --- a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h +++ b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h @@ -539,7 +539,7 @@ PIN_PUPDR_PULLUP(GPIOC_PIN10) | \ PIN_PUPDR_PULLUP(GPIOC_PIN11) | \ PIN_PUPDR_PULLUP(GPIOC_PIN12) | \ - PIN_PUPDR_PULLUP(GPIOC_PIN13) | \ + PIN_PUPDR_FLOATING(GPIOC_PIN13) | \ PIN_PUPDR_FLOATING(GPIOC_PIN14) | \ PIN_PUPDR_FLOATING(GPIOC_PIN15)) #define VAL_GPIOC_ODR (PIN_ODR_HIGH(GPIOC_PIN0) | \ @@ -1164,7 +1164,7 @@ /* * USB bus activation macro, required by the USB driver. */ -// #define usb_lld_connect_bus(usbp) +// #define usb_lld_connect_bus(usbp) #define usb_lld_connect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_ALTERNATE(14))) // #define usb_lld_connect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_INPUT) /* diff --git a/keyboards/_qmk_handwire/config.h b/keyboards/_qmk_handwire/config.h index 6b3042ce01..7243e13647 100644 --- a/keyboards/_qmk_handwire/config.h +++ b/keyboards/_qmk_handwire/config.h @@ -126,8 +126,11 @@ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 1 -#endif - /* Backlight configuration */ #define BACKLIGHT_LEVELS 1 + +#define NO_USB_STARTUP_CHECK + +#endif + diff --git a/keyboards/_qmk_handwire/halconf.h b/keyboards/_qmk_handwire/halconf.h index d2a7653f5d..bf2b69e225 100644 --- a/keyboards/_qmk_handwire/halconf.h +++ b/keyboards/_qmk_handwire/halconf.h @@ -79,6 +79,13 @@ #define HAL_USE_I2C TRUE #endif +/** + * @brief Enables the I2C Slave subsystem. + */ +#if !defined(HAL_USE_I2C_SLAVE) || defined(__DOXYGEN__) +#define HAL_USE_I2C_SLAVE TRUE +#endif + /** * @brief Enables the I2S subsystem. */ diff --git a/keyboards/_qmk_handwire/keymaps/default/keymap.c b/keyboards/_qmk_handwire/keymaps/default/keymap.c index 8469b6c395..d0e727825e 100644 --- a/keyboards/_qmk_handwire/keymaps/default/keymap.c +++ b/keyboards/_qmk_handwire/keymaps/default/keymap.c @@ -34,18 +34,18 @@ enum custom_keycodes { const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = KEYMAP( - KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, - KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, - KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, - KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, - KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, - MO(2), MO(1), KC_SPC, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_0, KC_DEL, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_HOME, + KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_END, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_N, + KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_LGUI, + KC_SPC, MO(2), MO(1), - KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, - KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, - KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, - KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, - KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, + KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, + KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, + KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, + KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, MO(2), MO(1), KC_SPC ) }; diff --git a/keyboards/_qmk_handwire/matrix.c b/keyboards/_qmk_handwire/matrix.c index c76a93db70..8800183aab 100644 --- a/keyboards/_qmk_handwire/matrix.c +++ b/keyboards/_qmk_handwire/matrix.c @@ -8,6 +8,7 @@ #include "backlight.h" #include "matrix.h" +#include "usb_main.h" /* QMK Handwire * @@ -24,6 +25,9 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static bool debouncing = false; static uint16_t debouncing_time = 0; +static bool master = false; +static bool right_hand = false; + __attribute__ ((weak)) void matrix_init_user(void) {} @@ -44,6 +48,14 @@ void matrix_init(void) { printf("matrix init\n"); //debug_matrix = true; + // C13 is connected to VCC on the right hand + palSetPadMode(GPIOC, 13, PAL_MODE_INPUT); + wait_us(20); + right_hand = palReadPad(GPIOC, 13); + + // if USB is active, this is the master + master = (USB_DRIVER.state == USB_ACTIVE); + /* Column(sense) */ palSetPadMode(GPIOA, 13, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(GPIOA, 14, PAL_MODE_INPUT_PULLDOWN); @@ -68,42 +80,60 @@ void matrix_init(void) { matrix_init_quantum(); } +matrix_row_t matrix_scan_common(uint8_t row) { + matrix_row_t data; + + // strobe row { A6, A7, B0, B1, B2, B10 } + switch (row) { + case 5: palSetPad(GPIOA, 6); break; + case 4: palSetPad(GPIOA, 7); break; + case 3: palSetPad(GPIOB, 0); break; + case 2: palSetPad(GPIOB, 1); break; + case 1: palSetPad(GPIOB, 2); break; + case 0: palSetPad(GPIOB, 10); break; + } + + // need wait to settle pin state + wait_us(20); + + // read col data { B6, B5, B4, B3, A15, A14, A13 } + data = ( + (palReadPad(GPIOB, 6) << 6 ) | + (palReadPad(GPIOB, 5) << 5 ) | + (palReadPad(GPIOB, 4) << 4 ) | + (palReadPad(GPIOB, 3) << 3 ) | + (palReadPad(GPIOA, 15) << 2 ) | + (palReadPad(GPIOA, 14) << 1 ) | + (palReadPad(GPIOA, 13) << 0 ) + ); + + // unstrobe row { A6, A7, B0, B1, B2, B10 } + switch (row) { + case 5: palClearPad(GPIOA, 6); break; + case 4: palClearPad(GPIOA, 7); break; + case 3: palClearPad(GPIOB, 0); break; + case 2: palClearPad(GPIOB, 1); break; + case 1: palClearPad(GPIOB, 2); break; + case 0: palClearPad(GPIOB, 10); break; + } + + return data; +} + +uint8_t matrix_scan_master(void) { + +} + +uint8_t matrix_scan_slave(void) { + +} + uint8_t matrix_scan(void) { for (int row = 0; row < MATRIX_ROWS; row++) { matrix_row_t data = 0; - // strobe row { A6, A7, B0, B1, B2, B10 } - switch (row) { - case 5: palSetPad(GPIOA, 6); break; - case 4: palSetPad(GPIOA, 7); break; - case 3: palSetPad(GPIOB, 0); break; - case 2: palSetPad(GPIOB, 1); break; - case 1: palSetPad(GPIOB, 2); break; - case 0: palSetPad(GPIOB, 10); break; - } - - // need wait to settle pin state - wait_us(20); - - // read col data { B6, B5, B4, B3, A15, A14, A13 } - data = ( - (palReadPad(GPIOB, 6) << 6 ) | - (palReadPad(GPIOB, 5) << 5 ) | - (palReadPad(GPIOB, 4) << 4 ) | - (palReadPad(GPIOB, 3) << 3 ) | - (palReadPad(GPIOA, 15) << 2 ) | - (palReadPad(GPIOA, 14) << 1 ) | - (palReadPad(GPIOA, 13) << 0 ) - ); - - // unstrobe row { A6, A7, B0, B1, B2, B10 } - switch (row) { - case 5: palClearPad(GPIOA, 6); break; - case 4: palClearPad(GPIOA, 7); break; - case 3: palClearPad(GPIOB, 0); break; - case 2: palClearPad(GPIOB, 1); break; - case 1: palClearPad(GPIOB, 2); break; - case 0: palClearPad(GPIOB, 10); break; + if (right_hand && row >= 6) { + data = matrix_scan_common(row % 6); } if (matrix_debouncing[row] != data) { diff --git a/keyboards/_qmk_handwire/rules.mk b/keyboards/_qmk_handwire/rules.mk index acabc0f950..9ca7e779a3 100644 --- a/keyboards/_qmk_handwire/rules.mk +++ b/keyboards/_qmk_handwire/rules.mk @@ -53,3 +53,4 @@ NKRO_ENABLE = yes # USB Nkey Rollover CUSTOM_MATRIX = yes # Custom matrix file AUDIO_ENABLE = yes # SERIAL_LINK_ENABLE = yes +I2C_SLAVE_ENABLE = yes diff --git a/lib/chibios b/lib/chibios index 587968d6cb..f9643c88ad 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit 587968d6cbc2b0e1c7147540872f2a67e59ca18b +Subproject commit f9643c88ad5cd0704d57bed83fe64f45b3e6be4e diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk index 106b771507..00d67f76aa 100644 --- a/tmk_core/avr.mk +++ b/tmk_core/avr.mk @@ -9,11 +9,9 @@ SIZE = avr-size AR = avr-ar rcs NM = avr-nm HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature -EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) +EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) BIN = -COMMON_VPATH += $(DRIVER_PATH)/avr - COMPILEFLAGS += -funsigned-char COMPILEFLAGS += -funsigned-bitfields COMPILEFLAGS += -ffunction-sections @@ -126,14 +124,14 @@ program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep check-size teensy: $(BUILD_DIR)/$(TARGET).hex check-size $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex - -BATCHISP ?= batchisp + +BATCHISP ?= batchisp flip: $(BUILD_DIR)/$(TARGET).hex check-size $(BATCHISP) -hardware usb -device $(MCU) -operation erase f $(BATCHISP) -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program $(BATCHISP) -hardware usb -device $(MCU) -operation start reset 0 - + DFU_PROGRAMMER ?= dfu-programmer dfu: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size @@ -194,7 +192,7 @@ bin: $(BUILD_DIR)/$(TARGET).hex # copy bin to FLASH.bin flashbin: bin - $(COPY) $(BUILD_DIR)/$(TARGET).bin FLASH.bin; + $(COPY) $(BUILD_DIR)/$(TARGET).bin FLASH.bin; # Generate avr-gdb config/init file which does the following: # define the reset signal, load the target file, connect to target, and set @@ -245,7 +243,7 @@ extcoff: $(BUILD_DIR)/$(TARGET).elf @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof -bootloader: +bootloader: make -C lib/lufa/Bootloaders/DFU/ clean echo "#ifndef QMK_KEYBOARD\n#define QMK_KEYBOARD\n" > lib/lufa/Bootloaders/DFU/Keyboard.h echo `grep "MANUFACTURER" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index f2abc438d4..8bb00583de 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c @@ -135,7 +135,10 @@ int main(void) { /* Wait until the USB or serial link is active */ while (true) { - if(USB_DRIVER.state == USB_ACTIVE) { + #if !defined(NO_USB_STARTUP_CHECK) + if(USB_DRIVER.state == USB_ACTIVE) + #endif + { driver = &chibios_driver; break; } From 7d59f83b2e43ac8c6d6d39e7e45311f2300a994d Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 14 Feb 2018 15:35:24 -0500 Subject: [PATCH 08/42] adds matrix i2c swap --- drivers/arm/twi2c.c | 52 +++++++------------ drivers/arm/twi2c.h | 12 ++++- .../_qmk_handwire/keymaps/default/keymap.c | 4 +- keyboards/_qmk_handwire/matrix.c | 44 ++++++++++++++-- 4 files changed, 70 insertions(+), 42 deletions(-) diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index b6dc2d27ed..561a601eaa 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -21,6 +21,7 @@ #include "chprintf.h" #include "memstreams.h" #include "printf.h" +#include "matrix.h" #ifndef I2C_DRIVER #define I2C_DRIVER I2CD1 @@ -37,13 +38,7 @@ * Stretches clock until reply available. */ - -#define slaveI2Caddress 0x30 /* Address in our terms - halved by later code */ -//#define myOtherI2Caddress 0x19 - -I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; - -static const I2CConfig slaveI2Cconfig = { +static const I2CConfig uniI2CConfig = { STM32_TIMINGR_PRESC(15U) | STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) | STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U), @@ -119,11 +114,10 @@ void catchError(I2CDriver *i2cp) noteI2cError(i2cp->errors); } - +extern void matrix_copy(matrix_row_t * copy); const char hexString[16] = "0123456789abcdef"; - /** * Message processor - looks at received message, determines reply as quickly as possible * @@ -132,36 +126,18 @@ const char hexString[16] = "0123456789abcdef"; * Note: Called in interrupt context, so need to be quick! */ void twi2c_slave_message_process(I2CDriver *i2cp) { - uint8_t i; - uint8_t *txPtr = txBody + 8; + uint8_t *txPtr = txBody; uint8_t txLen; - uint32_t curCount; size_t len = i2cSlaveBytes(i2cp); // Number of bytes received - if (len >= sizeof(rxBody)) - len = sizeof(rxBody)-1; - rxBody[len]=0; // String termination sometimes useful - /* A real-world application would read and decode the message in rxBody, then generate an appropriate reply in txBody */ - - curCount = ++messageCounter; - txLen = len + 11; // Add in the overhead - - for (i = 0; i < 8; i++) - { - *--txPtr = hexString[curCount & 0xf]; - curCount = curCount >> 4; + if (len >= 2 && rxBody[0] == 0x01 && rxBody[1] == 0x00) { + matrix_row_t matrix[MATRIX_ROWS / 2]; + matrix_copy(matrix); + memcpy(txPtr, matrix, MATRIX_ROWS / 2); + txLen = MATRIX_ROWS / 2; } - txPtr = txBody + 8; - *txPtr++ = ' '; - *txPtr++ = '['; - memcpy(txPtr, rxBody, len); // Echo received message - txPtr += len; - *txPtr++ = ']'; - *txPtr = '\0'; - - /** Message ready to go here */ echoReply.size = txLen; i2cSlaveReplyI(i2cp, &echoReply); } @@ -193,7 +169,7 @@ void twi2c_slave_init(void) { palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); - i2cStart(&I2C_DRIVER, &slaveI2Cconfig); + i2cStart(&I2C_DRIVER, &uniI2CConfig); #if HAL_USE_I2C_SLAVE I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message #endif @@ -215,3 +191,11 @@ void twi2c_slave_task(void) { printf("I2cError: %04x\r\n", lastI2cErrorFlags); } } + +void twi2c_master_init(void) { + i2cStart(&I2C_DRIVER, &uniI2CConfig); +} + +msg_t twi2c_master_send(i2caddr_t address, const uint8_t * txbuf, uint8_t * rxbuf, systime_t timeout) { + return i2cMasterTransmitTimeout(&I2C_DRIVER, address, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), timeout); +} diff --git a/drivers/arm/twi2c.h b/drivers/arm/twi2c.h index a1847d436d..175572189b 100644 --- a/drivers/arm/twi2c.h +++ b/drivers/arm/twi2c.h @@ -15,4 +15,14 @@ */ #include "ch.h" -#include "hal.h" \ No newline at end of file +#include "hal.h" + +#define slaveI2Caddress 0x30 /* Address in our terms - halved by later code */ +//#define myOtherI2Caddress 0x19 + +I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; + +void twi2c_slave_init(void); + +void twi2c_master_init(void); +msg_t twi2c_master_send(i2caddr_t address, const uint8_t * txbuf, uint8_t * rxbuf, systime_t timeout); diff --git a/keyboards/_qmk_handwire/keymaps/default/keymap.c b/keyboards/_qmk_handwire/keymaps/default/keymap.c index d0e727825e..2611f570c3 100644 --- a/keyboards/_qmk_handwire/keymaps/default/keymap.c +++ b/keyboards/_qmk_handwire/keymaps/default/keymap.c @@ -35,14 +35,14 @@ enum custom_keycodes { const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = KEYMAP( KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_0, KC_DEL, - KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_HOME, + KC_TAB, DEBUG, KC_W, KC_E, KC_R, KC_T, KC_HOME, KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_END, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_N, KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_LGUI, KC_SPC, MO(2), MO(1), KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, - KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, + KC_PGUP, KC_Y, KC_U, KC_I, KC_O, DEBUG, KC_DEL, KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, diff --git a/keyboards/_qmk_handwire/matrix.c b/keyboards/_qmk_handwire/matrix.c index 8800183aab..1d67851ba2 100644 --- a/keyboards/_qmk_handwire/matrix.c +++ b/keyboards/_qmk_handwire/matrix.c @@ -9,6 +9,7 @@ #include "matrix.h" #include "usb_main.h" +#include "twi2c.h" /* QMK Handwire * @@ -46,7 +47,7 @@ void matrix_scan_kb(void) { void matrix_init(void) { printf("matrix init\n"); - //debug_matrix = true; + // debug_matrix = true; // C13 is connected to VCC on the right hand palSetPadMode(GPIOC, 13, PAL_MODE_INPUT); @@ -56,6 +57,12 @@ void matrix_init(void) { // if USB is active, this is the master master = (USB_DRIVER.state == USB_ACTIVE); + if (master) { + twi2c_master_init(); + } else { + twi2c_slave_init(); + } + /* Column(sense) */ palSetPadMode(GPIOA, 13, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(GPIOA, 14, PAL_MODE_INPUT_PULLDOWN); @@ -120,19 +127,31 @@ matrix_row_t matrix_scan_common(uint8_t row) { return data; } -uint8_t matrix_scan_master(void) { +void matrix_scan_master(void) { -} + const uint8_t command[2] = { 0x01, 0x00 }; + uint8_t other_matrix[MATRIX_ROWS]; -uint8_t matrix_scan_slave(void) { + msg_t resp; + resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_INFINITE); + printf("%x\n", resp); + uint8_t * matrix_pointer; + if (right_hand) { + matrix_pointer = matrix; + } else { + matrix_pointer = matrix + (MATRIX_ROWS / 2); + } + + memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2); } uint8_t matrix_scan(void) { + for (int row = 0; row < MATRIX_ROWS; row++) { matrix_row_t data = 0; - if (right_hand && row >= 6) { + if ((right_hand && row >= 6) || (!right_hand && row < 6)) { data = matrix_scan_common(row % 6); } @@ -149,6 +168,11 @@ uint8_t matrix_scan(void) { } debouncing = false; } + + if (master) { + matrix_scan_master(); + } + matrix_scan_quantum(); return 1; @@ -162,6 +186,16 @@ matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } +void matrix_copy(matrix_row_t * copy) { + uint8_t * matrix_pointer; + if (right_hand) { + matrix_pointer = matrix + (MATRIX_ROWS / 2); + } else { + matrix_pointer = matrix; + } + memcpy(copy, matrix_pointer, MATRIX_ROWS / 2); +} + void matrix_print(void) { printf("\nr/c 01234567\n"); for (uint8_t row = 0; row < MATRIX_ROWS; row++) { From 3c0d86eb47b2eb92b8300bc726dc242c8af594f4 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 15 Feb 2018 02:06:06 -0500 Subject: [PATCH 09/42] a little progress --- drivers/arm/twi2c.c | 15 ++++----------- keyboards/_qmk_handwire/matrix.c | 29 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 561a601eaa..299e52eb2a 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -53,7 +53,7 @@ char initialReplyBody[50] = "Initial reply"; // 'Status' response if read uint32_t messageCounter = 0; /* Counts number of messages received to return as part of response */ uint8_t rxBody[240]; /* stores last message master sent us (intentionally a few bytes smaller than txBody) */ -uint8_t txBody[256]; /* Return message buffer for computed replies */ +uint8_t txBody[MATRIX_ROWS/2]; /* Return message buffer for computed replies */ BaseSequentialStream *chp = NULL; // Used for serial logging @@ -126,19 +126,12 @@ const char hexString[16] = "0123456789abcdef"; * Note: Called in interrupt context, so need to be quick! */ void twi2c_slave_message_process(I2CDriver *i2cp) { - uint8_t *txPtr = txBody; - uint8_t txLen; - size_t len = i2cSlaveBytes(i2cp); // Number of bytes received + // size_t len = i2cSlaveBytes(i2cp); // Number of bytes received - if (len >= 2 && rxBody[0] == 0x01 && rxBody[1] == 0x00) { - matrix_row_t matrix[MATRIX_ROWS / 2]; - matrix_copy(matrix); - memcpy(txPtr, matrix, MATRIX_ROWS / 2); - txLen = MATRIX_ROWS / 2; - } + matrix_copy(txBody); - echoReply.size = txLen; + echoReply.size = MATRIX_ROWS / 2; i2cSlaveReplyI(i2cp, &echoReply); } diff --git a/keyboards/_qmk_handwire/matrix.c b/keyboards/_qmk_handwire/matrix.c index 1d67851ba2..cbf4537bf6 100644 --- a/keyboards/_qmk_handwire/matrix.c +++ b/keyboards/_qmk_handwire/matrix.c @@ -55,7 +55,8 @@ void matrix_init(void) { right_hand = palReadPad(GPIOC, 13); // if USB is active, this is the master - master = (USB_DRIVER.state == USB_ACTIVE); + // master = usbGetDriverStateI(&USB_DRIVER) == USB_ACTIVE; + master = right_hand; if (master) { twi2c_master_init(); @@ -127,23 +128,25 @@ matrix_row_t matrix_scan_common(uint8_t row) { return data; } +const uint8_t command[2] = { 0x01, 0x00 }; +uint8_t other_matrix[MATRIX_ROWS] = { 0 }; + void matrix_scan_master(void) { - const uint8_t command[2] = { 0x01, 0x00 }; - uint8_t other_matrix[MATRIX_ROWS]; - msg_t resp; - resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_INFINITE); - printf("%x\n", resp); + resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_IMMEDIATE); + // printf("%x\n", resp); - uint8_t * matrix_pointer; - if (right_hand) { - matrix_pointer = matrix; - } else { - matrix_pointer = matrix + (MATRIX_ROWS / 2); + if (resp == MSG_OK) { + uint8_t * matrix_pointer; + if (right_hand) { + matrix_pointer = matrix; + } else { + matrix_pointer = matrix + (MATRIX_ROWS / 2); + } + + memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2); } - - memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2); } uint8_t matrix_scan(void) { From 8b5b41bb4781c5fa08d9d1a149aa416631095f11 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 19 Feb 2018 22:00:38 -0500 Subject: [PATCH 10/42] update handwire with arm changes --- keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h | 2 +- keyboards/_qmk_handwire/config.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h index 254c84a097..23d0037b21 100644 --- a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h +++ b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.h @@ -1171,7 +1171,7 @@ * USB bus de-activation macro, required by the USB driver. */ // #define usb_lld_disconnect_bus(usbp) -#define usb_lld_disconnect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_OUTPUT_PUSHPULL)) +#define usb_lld_disconnect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_OUTPUT_PUSHPULL)); palClearPad(GPIOA, GPIOA_USB_DP) // #define usb_lld_disconnect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 12) #if !defined(_FROM_ASM_) diff --git a/keyboards/_qmk_handwire/config.h b/keyboards/_qmk_handwire/config.h index 7243e13647..fe0ad1d5c4 100644 --- a/keyboards/_qmk_handwire/config.h +++ b/keyboards/_qmk_handwire/config.h @@ -22,10 +22,8 @@ #define VENDOR_ID 0x125A #define PRODUCT_ID 0x1770 #define DEVICE_VER 0x0001 -#define MANUFACTURER "QMK" -#define USBSTR_MANUFACTURER 'Q', '\x00', 'M', '\x00', 'K', '\x00' -#define PRODUCT "Handwire" -#define USBSTR_PRODUCT 'H', '\x00', 'a', '\x00', 'n', '\x00', 'd', '\x00', 'w', '\x00', 'i', '\x00', 'r', '\x00', 'e', '\x00' +#define MANUFACTURER QMK +#define PRODUCT Handwire #define DESCRIPTION "Handwire protoboard" /* key matrix size */ From 00fc38435f0266872bdf35b0a943ac599ce57883 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 22 Feb 2018 21:22:47 -0500 Subject: [PATCH 11/42] master working --- drivers/arm/twi2c.c | 54 +++++++++++++------ drivers/arm/twi2c.h | 5 +- .../boards/GENERIC_STM32_F303XC/board.c | 4 +- .../_qmk_handwire/keymaps/default/keymap.c | 4 +- keyboards/_qmk_handwire/matrix.c | 9 +++- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 299e52eb2a..2b9209f5db 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -23,10 +23,6 @@ #include "printf.h" #include "matrix.h" -#ifndef I2C_DRIVER - #define I2C_DRIVER I2CD1 -#endif - /** * I2C slave test routine. * @@ -37,8 +33,13 @@ * b) A write then read transaction - calls a message processor and returns the generated reply. * Stretches clock until reply available. */ +// static const I2CConfig masterI2CConfig = { +// 400000 +// }; -static const I2CConfig uniI2CConfig = { +I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; + +static const I2CConfig slaveI2CConfig = { STM32_TIMINGR_PRESC(15U) | STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) | STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U), @@ -52,7 +53,7 @@ char initialReplyBody[50] = "Initial reply"; // 'Status' response if read uint32_t messageCounter = 0; /* Counts number of messages received to return as part of response */ -uint8_t rxBody[240]; /* stores last message master sent us (intentionally a few bytes smaller than txBody) */ +uint8_t rxBody[2]; /* stores last message master sent us (intentionally a few bytes smaller than txBody) */ uint8_t txBody[MATRIX_ROWS/2]; /* Return message buffer for computed replies */ BaseSequentialStream *chp = NULL; // Used for serial logging @@ -68,16 +69,26 @@ const I2CSlaveMsg echoRx = }; -// 'Empty' reply when nothing to say, and no message received. In RAM, to allow update +// // 'Empty' reply when nothing to say, and no message received. In RAM, to allow update I2CSlaveMsg initialReply = { - sizeof(initialReplyBody), /* trailing zero byte will be repeated as needed */ + sizeof(initialReplyBody), /* trailing zero byte will be repeated as needed */ (uint8_t *)initialReplyBody, NULL, /* do nothing on address match */ NULL, /* do nothing after reply sent */ catchError /* Error hook */ }; +// // 'Empty' reply when nothing to say, and no message received. In RAM, to allow update +// I2CSlaveMsg initialReply = +// { +// 0, /* trailing zero byte will be repeated as needed */ +// NULL, +// NULL, /* do nothing on address match */ +// NULL, /* do nothing after reply sent */ +// catchError /* Error hook */ +// }; + // Response to received messages I2CSlaveMsg echoReply = { /* this is in RAM so size may be updated */ @@ -129,7 +140,8 @@ void twi2c_slave_message_process(I2CDriver *i2cp) { // size_t len = i2cSlaveBytes(i2cp); // Number of bytes received - matrix_copy(txBody); + memset(txBody, 0, MATRIX_ROWS / 2 * sizeof(matrix_row_t)); + // matrix_copy(txBody); echoReply.size = MATRIX_ROWS / 2; i2cSlaveReplyI(i2cp, &echoReply); @@ -162,17 +174,18 @@ void twi2c_slave_init(void) { palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); - i2cStart(&I2C_DRIVER, &uniI2CConfig); + i2cStart(&I2C_DRIVER, &slaveI2CConfig); #if HAL_USE_I2C_SLAVE I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message #endif - i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply); + // i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply); + i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &echoReply); // Enable match address after everything else set up i2cMatchAddress(&I2C_DRIVER, slaveI2Caddress/2); // i2cMatchAddress(&I2C_DRIVER, myOtherI2Caddress/2); -// i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */ + // i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */ printf("Slave I2C started\n\r"); @@ -186,9 +199,18 @@ void twi2c_slave_task(void) { } void twi2c_master_init(void) { - i2cStart(&I2C_DRIVER, &uniI2CConfig); -} -msg_t twi2c_master_send(i2caddr_t address, const uint8_t * txbuf, uint8_t * rxbuf, systime_t timeout) { - return i2cMasterTransmitTimeout(&I2C_DRIVER, address, txbuf, sizeof(txbuf), rxbuf, sizeof(rxbuf), timeout); + palSetGroupMode(GPIOB,8,9, PAL_MODE_INPUT); // Try releasing special pins for a short time + chThdSleepMilliseconds(10); + + palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + + i2cStart(&I2C_DRIVER, &slaveI2CConfig); + + // try high drive (from kiibohd) + // I2C_DRIVER.i2c->C2 |= I2Cx_C2_HDRS; + // try glitch fixing (from kiibohd) + // I2C_DRIVER.i2c->FLT = 4; + } diff --git a/drivers/arm/twi2c.h b/drivers/arm/twi2c.h index 175572189b..bc7a064a58 100644 --- a/drivers/arm/twi2c.h +++ b/drivers/arm/twi2c.h @@ -17,6 +17,10 @@ #include "ch.h" #include "hal.h" +#ifndef I2C_DRIVER + #define I2C_DRIVER I2CD1 +#endif + #define slaveI2Caddress 0x30 /* Address in our terms - halved by later code */ //#define myOtherI2Caddress 0x19 @@ -25,4 +29,3 @@ I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; void twi2c_slave_init(void); void twi2c_master_init(void); -msg_t twi2c_master_send(i2caddr_t address, const uint8_t * txbuf, uint8_t * rxbuf, systime_t timeout); diff --git a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c index 897f20a887..4331155df4 100644 --- a/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c +++ b/keyboards/_qmk_handwire/boards/GENERIC_STM32_F303XC/board.c @@ -62,13 +62,15 @@ const PALConfig pal_default_config = { }; #endif +void enter_bootloader_mode_if_requested(void); + /** * @brief Early initialization code. * @details This initialization must be performed just after stack setup * and before any other initialization. */ void __early_init(void) { - + enter_bootloader_mode_if_requested(); stm32_clock_init(); } diff --git a/keyboards/_qmk_handwire/keymaps/default/keymap.c b/keyboards/_qmk_handwire/keymaps/default/keymap.c index 2611f570c3..4874eb91c8 100644 --- a/keyboards/_qmk_handwire/keymaps/default/keymap.c +++ b/keyboards/_qmk_handwire/keymaps/default/keymap.c @@ -34,14 +34,14 @@ enum custom_keycodes { const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = KEYMAP( - KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_0, KC_DEL, + RESET, KC_1, KC_2, KC_3, KC_4, KC_0, KC_DEL, KC_TAB, DEBUG, KC_W, KC_E, KC_R, KC_T, KC_HOME, KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_END, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_N, KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_LGUI, KC_SPC, MO(2), MO(1), - KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, RESET, KC_PGUP, KC_Y, KC_U, KC_I, KC_O, DEBUG, KC_DEL, KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, diff --git a/keyboards/_qmk_handwire/matrix.c b/keyboards/_qmk_handwire/matrix.c index cbf4537bf6..a651d33940 100644 --- a/keyboards/_qmk_handwire/matrix.c +++ b/keyboards/_qmk_handwire/matrix.c @@ -134,8 +134,15 @@ uint8_t other_matrix[MATRIX_ROWS] = { 0 }; void matrix_scan_master(void) { msg_t resp; - resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_IMMEDIATE); + // resp = twi2c_master_send(slaveI2Caddress/2, command, 2, other_matrix, US2ST(100)); + // resp = i2cMasterTransmitTimeout(&I2C_DRIVER, slaveI2Caddress/2, command, 2, other_matrix, MATRIX_ROWS / 2, US2ST(100)); + resp = i2cMasterReceiveTimeout(&I2C_DRIVER, slaveI2Caddress/2, other_matrix, MATRIX_ROWS / 2, US2ST(100)); // printf("%x\n", resp); + // if (resp != MSG_OK) { + // for (i = 0; i < MATRIX_ROWS / 2; i++) { + // resp = i2cMasterReceiveTimeout(&I2C_DRIVER, slaveI2Caddress/2, other_matrix, MATRIX_ROWS / 2, US2ST(100)); + // } + // } if (resp == MSG_OK) { uint8_t * matrix_pointer; From 123ad0de952039aa135fdda80fb83c65a65fd054 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 23 Feb 2018 11:29:30 -0500 Subject: [PATCH 12/42] try more stuff --- drivers/arm/twi2c.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 2b9209f5db..c1ab3c6594 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -179,13 +179,13 @@ void twi2c_slave_init(void) { I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message #endif - // i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply); - i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &echoReply); + i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply); + // i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &echoReply); // Enable match address after everything else set up - i2cMatchAddress(&I2C_DRIVER, slaveI2Caddress/2); + // i2cMatchAddress(&I2C_DRIVER, slaveI2Caddress/2); // i2cMatchAddress(&I2C_DRIVER, myOtherI2Caddress/2); - // i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */ + i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */ printf("Slave I2C started\n\r"); From b308d6709efed34037e6645384d98c2e1ae7503e Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 23 Feb 2018 12:09:03 -0500 Subject: [PATCH 13/42] working --- drivers/arm/twi2c.c | 21 ++++++++++++--------- keyboards/_qmk_handwire/matrix.c | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index c1ab3c6594..7200d2db95 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -92,7 +92,7 @@ I2CSlaveMsg initialReply = // Response to received messages I2CSlaveMsg echoReply = { /* this is in RAM so size may be updated */ - 0, /* filled in with the length of the message to send */ + MATRIX_ROWS / 2, /* filled in with the length of the message to send */ txBody, /* Response message */ NULL, /* do nothing special on address match */ clearAfterSend, /* Clear receive buffer once replied */ @@ -140,8 +140,8 @@ void twi2c_slave_message_process(I2CDriver *i2cp) { // size_t len = i2cSlaveBytes(i2cp); // Number of bytes received - memset(txBody, 0, MATRIX_ROWS / 2 * sizeof(matrix_row_t)); - // matrix_copy(txBody); + // memset(txBody, 0, MATRIX_ROWS / 2 * sizeof(matrix_row_t)); + matrix_copy(txBody); echoReply.size = MATRIX_ROWS / 2; i2cSlaveReplyI(i2cp, &echoReply); @@ -153,8 +153,8 @@ void twi2c_slave_message_process(I2CDriver *i2cp) { */ void clearAfterSend(I2CDriver *i2cp) { - echoReply.size = 0; // Clear receive message - i2cSlaveReplyI(i2cp, &initialReply); + // echoReply.size = 0; // Clear receive message + // i2cSlaveReplyI(i2cp, &initialReply); } @@ -179,13 +179,16 @@ void twi2c_slave_init(void) { I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message #endif - i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply); - // i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &echoReply); + // i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply); + + memset(txBody, 0, MATRIX_ROWS / 2 * sizeof(matrix_row_t)); + + i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &echoReply); // Enable match address after everything else set up - // i2cMatchAddress(&I2C_DRIVER, slaveI2Caddress/2); + i2cMatchAddress(&I2C_DRIVER, slaveI2Caddress/2); // i2cMatchAddress(&I2C_DRIVER, myOtherI2Caddress/2); - i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */ + // i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */ printf("Slave I2C started\n\r"); diff --git a/keyboards/_qmk_handwire/matrix.c b/keyboards/_qmk_handwire/matrix.c index a651d33940..499c92f8ca 100644 --- a/keyboards/_qmk_handwire/matrix.c +++ b/keyboards/_qmk_handwire/matrix.c @@ -135,8 +135,8 @@ void matrix_scan_master(void) { msg_t resp; // resp = twi2c_master_send(slaveI2Caddress/2, command, 2, other_matrix, US2ST(100)); - // resp = i2cMasterTransmitTimeout(&I2C_DRIVER, slaveI2Caddress/2, command, 2, other_matrix, MATRIX_ROWS / 2, US2ST(100)); - resp = i2cMasterReceiveTimeout(&I2C_DRIVER, slaveI2Caddress/2, other_matrix, MATRIX_ROWS / 2, US2ST(100)); + resp = i2cMasterTransmitTimeout(&I2C_DRIVER, slaveI2Caddress/2, command, 2, other_matrix, MATRIX_ROWS / 2, MS2ST(100)); + // resp = i2cMasterReceiveTimeout(&I2C_DRIVER, slaveI2Caddress/2, other_matrix, MATRIX_ROWS / 2, US2ST(100)); // printf("%x\n", resp); // if (resp != MSG_OK) { // for (i = 0; i < MATRIX_ROWS / 2; i++) { From da32068f489e94eff7ebf57b83c6a55d405ca81f Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 26 Feb 2018 21:29:07 -0500 Subject: [PATCH 14/42] update to qwerty --- .../_qmk_handwire/keymaps/default/keymap.c | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/keyboards/_qmk_handwire/keymaps/default/keymap.c b/keyboards/_qmk_handwire/keymaps/default/keymap.c index 4874eb91c8..168be875c2 100644 --- a/keyboards/_qmk_handwire/keymaps/default/keymap.c +++ b/keyboards/_qmk_handwire/keymaps/default/keymap.c @@ -34,20 +34,35 @@ enum custom_keycodes { const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = KEYMAP( - RESET, KC_1, KC_2, KC_3, KC_4, KC_0, KC_DEL, - KC_TAB, DEBUG, KC_W, KC_E, KC_R, KC_T, KC_HOME, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_DEL, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_HOME, KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_END, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_N, - KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_LGUI, - KC_SPC, MO(2), MO(1), + KC_NO, KC_LCTL, KC_LALT, KC_LGUI, MO(1), + KC_SPC, MO(1), RESET, - KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, RESET, - KC_PGUP, KC_Y, KC_U, KC_I, KC_O, DEBUG, KC_DEL, + KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + KC_PGUP, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, KC_PGDN, KC_H, KC_J, KC_K, KC_L, KC_COLN, KC_QUOT, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, KC_RCTL, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, - MO(2), MO(1), KC_SPC + RESET, MO(2), KC_SPC ) + // [0] = KEYMAP( + // KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_DEL, + // KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_HOME, + // KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_END, + // KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, + // KC_NO, KC_LCTL, KC_LALT, KC_LGUI, MO(1), + // KC_SPC, MO(1), RESET, + + // KC_INS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + // KC_PGUP, KC_J, KC_L, KC_U, KC_Y, KC_COLN, KC_DEL, + // KC_PGDN, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, + // KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, + // KC_RGUI, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, + // RESET, MO(2), KC_SPC + // ) }; bool process_record_user(uint16_t keycode, keyrecord_t *record) { From 2bd625b75431df090a2297199cce98c1fba0c748 Mon Sep 17 00:00:00 2001 From: Some Person Date: Mon, 5 Mar 2018 19:56:09 -0500 Subject: [PATCH 15/42] bla --- lib/chibios | 2 +- lib/chibios-contrib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chibios b/lib/chibios index f9643c88ad..8fce03b3a7 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit f9643c88ad5cd0704d57bed83fe64f45b3e6be4e +Subproject commit 8fce03b3a75c743e5d5c40b9d59c1637c59d22a7 diff --git a/lib/chibios-contrib b/lib/chibios-contrib index ede48346ee..e1311c4db6 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit ede48346eee4b8d6847c19bc01420bee76a5e486 +Subproject commit e1311c4db6cd366cf760673f769e925741ac0ad3 From b034896cd303270eea2b217b9f0d234d003b4507 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 5 Mar 2018 20:24:20 -0500 Subject: [PATCH 16/42] update submodule --- .gitmodules | 1 + lib/chibios | 2 +- lib/chibios-contrib | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 0e870021f0..eab2ee2bba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,7 @@ [submodule "lib/chibios"] path = lib/chibios url = https://github.com/qmk/ChibiOS + branch = handwire [submodule "lib/chibios-contrib"] path = lib/chibios-contrib url = https://github.com/qmk/ChibiOS-Contrib diff --git a/lib/chibios b/lib/chibios index 8fce03b3a7..f9643c88ad 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit 8fce03b3a75c743e5d5c40b9d59c1637c59d22a7 +Subproject commit f9643c88ad5cd0704d57bed83fe64f45b3e6be4e diff --git a/lib/chibios-contrib b/lib/chibios-contrib index e1311c4db6..ede48346ee 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit e1311c4db6cd366cf760673f769e925741ac0ad3 +Subproject commit ede48346eee4b8d6847c19bc01420bee76a5e486 From 12a64ff24b1dbdaf69dda529dd95219371206a58 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 16 Mar 2018 03:38:20 -0400 Subject: [PATCH 17/42] initial files for rev 6 with encoder --- keyboards/planck/config.h | 2 + keyboards/planck/keymaps/default/keymap.c | 88 +- keyboards/planck/planck.c | 2 + keyboards/planck/planck.h | 94 ++ .../rev6/boards/GENERIC_STM32_F303XC/board.c | 126 ++ .../rev6/boards/GENERIC_STM32_F303XC/board.h | 1187 +++++++++++++++++ .../rev6/boards/GENERIC_STM32_F303XC/board.mk | 5 + keyboards/planck/rev6/bootloader_defs.h | 7 + keyboards/planck/rev6/chconf.h | 520 ++++++++ keyboards/planck/rev6/config.h | 124 ++ keyboards/planck/rev6/halconf.h | 388 ++++++ keyboards/planck/rev6/matrix.c | 168 +++ keyboards/planck/rev6/mcuconf.h | 257 ++++ keyboards/planck/rev6/rev6.c | 24 + keyboards/planck/rev6/rev6.h | 21 + keyboards/planck/rev6/rules.mk | 55 + 16 files changed, 3026 insertions(+), 42 deletions(-) create mode 100644 keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.c create mode 100644 keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h create mode 100644 keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.mk create mode 100644 keyboards/planck/rev6/bootloader_defs.h create mode 100644 keyboards/planck/rev6/chconf.h create mode 100644 keyboards/planck/rev6/config.h create mode 100644 keyboards/planck/rev6/halconf.h create mode 100644 keyboards/planck/rev6/matrix.c create mode 100644 keyboards/planck/rev6/mcuconf.h create mode 100644 keyboards/planck/rev6/rev6.c create mode 100644 keyboards/planck/rev6/rev6.h create mode 100644 keyboards/planck/rev6/rules.mk diff --git a/keyboards/planck/config.h b/keyboards/planck/config.h index 452a99d746..097bacd715 100644 --- a/keyboards/planck/config.h +++ b/keyboards/planck/config.h @@ -18,7 +18,9 @@ along with this program. If not, see . #ifndef CONFIG_H #define CONFIG_H +#ifdef __AVR__ #include "config_common.h" +#endif /* USB Device descriptor parameter */ #define VENDOR_ID 0xFEED diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index 04fc33640d..0bb70ca7b1 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -53,12 +53,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | * `-----------------------------------------------------------------------------------' */ -[_QWERTY] = { - {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, - {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, - {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} -}, +[_QWERTY] = LAYOUT_planck_grid( + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, + KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , + BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT +), /* Colemak * ,-----------------------------------------------------------------------------------. @@ -71,12 +71,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | * `-----------------------------------------------------------------------------------' */ -[_COLEMAK] = { - {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, - {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, - {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, - {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} -}, +[_COLEMAK] = LAYOUT_planck_grid( + KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, + KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , + KC_SPC, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT +), /* Dvorak * ,-----------------------------------------------------------------------------------. @@ -89,12 +89,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | * `-----------------------------------------------------------------------------------' */ -[_DVORAK] = { - {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, - {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, - {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, - {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} -}, +[_DVORAK] = LAYOUT_planck_grid( + KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC, + KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH, + KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT , + BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT +), /* Lower * ,-----------------------------------------------------------------------------------. @@ -107,12 +107,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | | | | | | | | Next | Vol- | Vol+ | Play | * `-----------------------------------------------------------------------------------' */ -[_LOWER] = { - {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, - {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, - {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______}, - {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} -}, +[_LOWER] = LAYOUT_planck_grid( + KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, + KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, + _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______, + _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY +), /* Raise * ,-----------------------------------------------------------------------------------. @@ -125,12 +125,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | | | | | | | | Next | Vol- | Vol+ | Play | * `-----------------------------------------------------------------------------------' */ -[_RAISE] = { - {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC}, - {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, - {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______}, - {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} -}, +[_RAISE] = LAYOUT_planck_grid( + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, + KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, + _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______, + _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY +), /* Plover layer (http://opensteno.org) * ,-----------------------------------------------------------------------------------. @@ -144,12 +144,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * `-----------------------------------------------------------------------------------' */ -[_PLOVER] = { - {KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 }, - {XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC}, - {XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, - {EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX} -}, +[_PLOVER] = LAYOUT_planck_grid( + KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 , + XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, + XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, + EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX +), /* Adjust (Lower + Raise) * ,-----------------------------------------------------------------------------------. @@ -162,12 +162,12 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * | | | | | | | | | | | | * `-----------------------------------------------------------------------------------' */ -[_ADJUST] = { - {_______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL }, - {_______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______}, - {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______}, - {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} -} +[_ADJUST] = LAYOUT_planck_grid( + _______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL , + _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______, + _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ +) }; @@ -224,10 +224,14 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { #ifdef BACKLIGHT_ENABLE backlight_step(); #endif + #ifdef __AVR__ PORTE &= ~(1<<6); + #endif } else { unregister_code(KC_RSFT); + #ifdef __AVR__ PORTE |= (1<<6); + #endif } return false; break; diff --git a/keyboards/planck/planck.c b/keyboards/planck/planck.c index 1d2f91bc55..9f7ffde8e9 100644 --- a/keyboards/planck/planck.c +++ b/keyboards/planck/planck.c @@ -13,8 +13,10 @@ const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { __attribute__ ((weak)) void matrix_init_kb(void) { // Turn status LED on + #ifdef __AVR__ DDRE |= (1<<6); PORTE |= (1<<6); + #endif matrix_init_user(); } diff --git a/keyboards/planck/planck.h b/keyboards/planck/planck.h index b663ba1c7c..626798912b 100644 --- a/keyboards/planck/planck.h +++ b/keyboards/planck/planck.h @@ -3,6 +3,7 @@ #include "quantum.h" +#ifdef __AVR__ #define LAYOUT_planck_mit( \ k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ @@ -47,4 +48,97 @@ #define LAYOUT_ortho_4x12 LAYOUT_planck_grid #define KC_LAYOUT_ortho_4x12 KC_KEYMAP +#else + + #define LAYOUT_planck_1x2uC( \ + k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ + k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ + k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \ + k30, k31, k32, k33, k34, k35, k37, k38, k39, k3a, k3b \ +) \ +{ \ + { k00, k01, k02, k03, k04, k05 }, \ + { k10, k11, k12, k13, k14, k15 }, \ + { k20, k21, k22, k23, k24, k25 }, \ + { k30, k31, k32, k33, k34, k35 }, \ + { k06, k07, k08, k09, k0a, k0b }, \ + { k16, k17, k18, k19, k1a, k1b }, \ + { k26, k27, k28, k29, k2a, k2b }, \ + { k36, k37, k38, k39, k3a, k3b } \ +} + +#define LAYOUT_planck_1x2uR( \ + k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ + k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ + k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \ + k30, k31, k32, k33, k34, k35, k37, k38, k39, k3a, k3b \ +) \ +{ \ + { k00, k01, k02, k03, k04, k05 }, \ + { k10, k11, k12, k13, k14, k15 }, \ + { k20, k21, k22, k23, k24, k25 }, \ + { k30, k31, k32, k33, k34, k35 }, \ + { k06, k07, k08, k09, k0a, k0b }, \ + { k16, k17, k18, k19, k1a, k1b }, \ + { k26, k27, k28, k29, k2a, k2b }, \ + { k36, k37, k38, k39, k3a, k3b } \ +} + +#define LAYOUT_planck_1x2uL( \ + k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ + k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ + k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \ + k30, k31, k32, k33, k34, k36, k37, k38, k39, k3a, k3b \ +) \ +{ \ + { k00, k01, k02, k03, k04, k05 }, \ + { k10, k11, k12, k13, k14, k15 }, \ + { k20, k21, k22, k23, k24, k25 }, \ + { k30, k31, k32, k33, k34, k35 }, \ + { k06, k07, k08, k09, k0a, k0b }, \ + { k16, k17, k18, k19, k1a, k1b }, \ + { k26, k27, k28, k29, k2a, k2b }, \ + { k36, k37, k38, k39, k3a, k3b } \ +} + +#define LAYOUT_planck_2x2u( \ + k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ + k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ + k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \ + k30, k31, k32, k33, k34, k36, k38, k39, k3a, k3b \ +) \ +{ \ + { k00, k01, k02, k03, k04, k05 }, \ + { k10, k11, k12, k13, k14, k15 }, \ + { k20, k21, k22, k23, k24, k25 }, \ + { k30, k31, k32, k33, k34, k35 }, \ + { k06, k07, k08, k09, k0a, k0b }, \ + { k16, k17, k18, k19, k1a, k1b }, \ + { k26, k27, k28, k29, k2a, k2b }, \ + { k36, k37, k38, k39, k3a, k3b } \ +} + +#define LAYOUT_planck_grid( \ + k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ + k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ + k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, \ + k30, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b \ +) \ +{ \ + { k00, k01, k02, k03, k04, k05 }, \ + { k10, k11, k12, k13, k14, k15 }, \ + { k20, k21, k22, k23, k24, k25 }, \ + { k30, k31, k32, k33, k34, k35 }, \ + { k06, k07, k08, k09, k0a, k0b }, \ + { k16, k17, k18, k19, k1a, k1b }, \ + { k26, k27, k28, k29, k2a, k2b }, \ + { k36, k37, k38, k39, k3a, k3b } \ +} + +#define KEYMAP LAYOUT_planck_grid +#define LAYOUT_ortho_4x12 LAYOUT_planck_grid +#define KC_LAYOUT_ortho_4x12 KC_KEYMAP + +#endif + #endif diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.c b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.c new file mode 100644 index 0000000000..4331155df4 --- /dev/null +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.c @@ -0,0 +1,126 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "hal.h" + +#if HAL_USE_PAL || defined(__DOXYGEN__) +/** + * @brief PAL setup. + * @details Digital I/O ports static configuration as defined in @p board.h. + * This variable is used by the HAL when initializing the PAL driver. + */ +const PALConfig pal_default_config = { +#if STM32_HAS_GPIOA + {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, + VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH}, +#endif +#if STM32_HAS_GPIOB + {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, + VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH}, +#endif +#if STM32_HAS_GPIOC + {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, + VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH}, +#endif +#if STM32_HAS_GPIOD + {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, + VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH}, +#endif +#if STM32_HAS_GPIOE + {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR, + VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH}, +#endif +#if STM32_HAS_GPIOF + {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR, + VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH}, +#endif +#if STM32_HAS_GPIOG + {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR, + VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH}, +#endif +#if STM32_HAS_GPIOH + {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR, + VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH}, +#endif +#if STM32_HAS_GPIOI + {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR, + VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH} +#endif +}; +#endif + +void enter_bootloader_mode_if_requested(void); + +/** + * @brief Early initialization code. + * @details This initialization must be performed just after stack setup + * and before any other initialization. + */ +void __early_init(void) { + enter_bootloader_mode_if_requested(); + stm32_clock_init(); +} + +#if HAL_USE_SDC || defined(__DOXYGEN__) +/** + * @brief SDC card detection. + */ +bool sdc_lld_is_card_inserted(SDCDriver *sdcp) { + + (void)sdcp; + /* TODO: Fill the implementation.*/ + return true; +} + +/** + * @brief SDC card write protection detection. + */ +bool sdc_lld_is_write_protected(SDCDriver *sdcp) { + + (void)sdcp; + /* TODO: Fill the implementation.*/ + return false; +} +#endif /* HAL_USE_SDC */ + +#if HAL_USE_MMC_SPI || defined(__DOXYGEN__) +/** + * @brief MMC_SPI card detection. + */ +bool mmc_lld_is_card_inserted(MMCDriver *mmcp) { + + (void)mmcp; + /* TODO: Fill the implementation.*/ + return true; +} + +/** + * @brief MMC_SPI card write protection detection. + */ +bool mmc_lld_is_write_protected(MMCDriver *mmcp) { + + (void)mmcp; + /* TODO: Fill the implementation.*/ + return false; +} +#endif + +/** + * @brief Board-specific initialization code. + * @todo Add your board-specific code, if any. + */ +void boardInit(void) { +} diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h new file mode 100644 index 0000000000..e09112eb98 --- /dev/null +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h @@ -0,0 +1,1187 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef _BOARD_H_ +#define _BOARD_H_ + +/* + * Setup for Clueboard 60% Keyboard + */ + +/* + * Board identifier. + */ +#define BOARD_GENERIC_STM32_F303XC +#define BOARD_NAME "Clueboard 60 PCB" + +/* + * Board oscillators-related settings. + * NOTE: LSE not fitted. + */ +#if !defined(STM32_LSECLK) +#define STM32_LSECLK 0U +#endif + +#define STM32_LSEDRV (3U << 3U) + +#if !defined(STM32_HSECLK) +#define STM32_HSECLK 8000000U +#endif + +// #define STM32_HSE_BYPASS + +/* + * MCU type as defined in the ST header. + */ +#define STM32F303xC + +/* + * IO pins assignments. + */ +#define GPIOA_PIN0 0U +#define GPIOA_PIN1 1U +#define GPIOA_PIN2 2U +#define GPIOA_PIN3 3U +#define GPIOA_PIN4 4U +#define GPIOA_PIN5 5U +#define GPIOA_PIN6 6U +#define GPIOA_PIN7 7U +#define GPIOA_PIN8 8U +#define GPIOA_PIN9 9U +#define GPIOA_PIN10 10U +#define GPIOA_USB_DM 11U +#define GPIOA_USB_DP 12U +#define GPIOA_SWDIO 13U +#define GPIOA_SWCLK 14U +#define GPIOA_PIN15 15U + +#define GPIOB_PIN0 0U +#define GPIOB_PIN1 1U +#define GPIOB_PIN2 2U +#define GPIOB_PIN3 3U +#define GPIOB_PIN4 4U +#define GPIOB_PIN5 5U +#define GPIOB_PIN6 6U +#define GPIOB_PIN7 7U +#define GPIOB_PIN8 8U +#define GPIOB_PIN9 9U +#define GPIOB_PIN10 10U +#define GPIOB_PIN11 11U +#define GPIOB_PIN12 12U +#define GPIOB_PIN13 13U +#define GPIOB_PIN14 14U +#define GPIOB_PIN15 15U + +#define GPIOC_PIN0 0U +#define GPIOC_PIN1 1U +#define GPIOC_PIN2 2U +#define GPIOC_PIN3 3U +#define GPIOC_PIN4 4U +#define GPIOC_PIN5 5U +#define GPIOC_PIN6 6U +#define GPIOC_PIN7 7U +#define GPIOC_PIN8 8U +#define GPIOC_PIN9 9U +#define GPIOC_PIN10 10U +#define GPIOC_PIN11 11U +#define GPIOC_PIN12 12U +#define GPIOC_PIN13 13U +#define GPIOC_PIN14 14U +#define GPIOC_PIN15 15U + +#define GPIOD_PIN0 0U +#define GPIOD_PIN1 1U +#define GPIOD_PIN2 2U +#define GPIOD_PIN3 3U +#define GPIOD_PIN4 4U +#define GPIOD_PIN5 5U +#define GPIOD_PIN6 6U +#define GPIOD_PIN7 7U +#define GPIOD_PIN8 8U +#define GPIOD_PIN9 9U +#define GPIOD_PIN10 10U +#define GPIOD_PIN11 11U +#define GPIOD_PIN12 12U +#define GPIOD_PIN13 13U +#define GPIOD_PIN14 14U +#define GPIOD_PIN15 15U + +#define GPIOE_PIN0 0U +#define GPIOE_PIN1 1U +#define GPIOE_PIN2 2U +#define GPIOE_PIN3 3U +#define GPIOE_PIN4 4U +#define GPIOE_PIN5 5U +#define GPIOE_PIN6 6U +#define GPIOE_PIN7 7U +#define GPIOE_PIN8 8U +#define GPIOE_PIN9 9U +#define GPIOE_PIN10 10U +#define GPIOE_PIN11 11U +#define GPIOE_PIN12 12U +#define GPIOE_PIN13 13U +#define GPIOE_PIN14 14U +#define GPIOE_PIN15 15U + +#define GPIOF_I2C2_SDA 0U +#define GPIOF_I2C2_SCL 1U +#define GPIOF_PIN2 2U +#define GPIOF_PIN3 3U +#define GPIOF_PIN4 4U +#define GPIOF_PIN5 5U +#define GPIOF_PIN6 6U +#define GPIOF_PIN7 7U +#define GPIOF_PIN8 8U +#define GPIOF_PIN9 9U +#define GPIOF_PIN10 10U +#define GPIOF_PIN11 11U +#define GPIOF_PIN12 12U +#define GPIOF_PIN13 13U +#define GPIOF_PIN14 14U +#define GPIOF_PIN15 15U + +#define GPIOG_PIN0 0U +#define GPIOG_PIN1 1U +#define GPIOG_PIN2 2U +#define GPIOG_PIN3 3U +#define GPIOG_PIN4 4U +#define GPIOG_PIN5 5U +#define GPIOG_PIN6 6U +#define GPIOG_PIN7 7U +#define GPIOG_PIN8 8U +#define GPIOG_PIN9 9U +#define GPIOG_PIN10 10U +#define GPIOG_PIN11 11U +#define GPIOG_PIN12 12U +#define GPIOG_PIN13 13U +#define GPIOG_PIN14 14U +#define GPIOG_PIN15 15U + +#define GPIOH_PIN0 0U +#define GPIOH_PIN1 1U +#define GPIOH_PIN2 2U +#define GPIOH_PIN3 3U +#define GPIOH_PIN4 4U +#define GPIOH_PIN5 5U +#define GPIOH_PIN6 6U +#define GPIOH_PIN7 7U +#define GPIOH_PIN8 8U +#define GPIOH_PIN9 9U +#define GPIOH_PIN10 10U +#define GPIOH_PIN11 11U +#define GPIOH_PIN12 12U +#define GPIOH_PIN13 13U +#define GPIOH_PIN14 14U +#define GPIOH_PIN15 15U + +/* + * IO lines assignments. + */ +#define LINE_L3GD20_SDI PAL_LINE(GPIOA, 7U) +#define LINE_USB_DM PAL_LINE(GPIOA, 11U) +#define LINE_USB_DP PAL_LINE(GPIOA, 12U) +#define LINE_SWDIO PAL_LINE(GPIOA, 13U) +#define LINE_SWCLK PAL_LINE(GPIOA, 14U) + +#define LINE_PIN6 PAL_LINE(GPIOF, 0U) +#define LINE_PIN7 PAL_LINE(GPIOF, 1U) + +#define LINE_CAPS_LOCK PAL_LINE(GPIOB, 7U) + + +/* + * I/O ports initial setup, this configuration is established soon after reset + * in the initialization code. + * Please refer to the STM32 Reference Manual for details. + */ +#define PIN_MODE_INPUT(n) (0U << ((n) * 2U)) +#define PIN_MODE_OUTPUT(n) (1U << ((n) * 2U)) +#define PIN_MODE_ALTERNATE(n) (2U << ((n) * 2U)) +#define PIN_MODE_ANALOG(n) (3U << ((n) * 2U)) +#define PIN_ODR_LOW(n) (0U << (n)) +#define PIN_ODR_HIGH(n) (1U << (n)) +#define PIN_OTYPE_PUSHPULL(n) (0U << (n)) +#define PIN_OTYPE_OPENDRAIN(n) (1U << (n)) +#define PIN_OSPEED_VERYLOW(n) (0U << ((n) * 2U)) +#define PIN_OSPEED_LOW(n) (1U << ((n) * 2U)) +#define PIN_OSPEED_MEDIUM(n) (2U << ((n) * 2U)) +#define PIN_OSPEED_HIGH(n) (3U << ((n) * 2U)) +#define PIN_PUPDR_FLOATING(n) (0U << ((n) * 2U)) +#define PIN_PUPDR_PULLUP(n) (1U << ((n) * 2U)) +#define PIN_PUPDR_PULLDOWN(n) (2U << ((n) * 2U)) +#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) + +/* + * GPIOA setup: + * + * PA0 - NC + * PA1 - NC + * PA2 - COL1 + * PA3 - COL2 + * PA4 - SPEAKER1 + * PA5 - SPEAKER2 + * PA6 - COL3 + * PA7 - COL8 + * PA8 - COL6 + * PA9 - COL7 + * PA10 - ROW5 + * PA11 - USB_DM (alternate 14). + * PA12 - USB_DP (alternate 14). + * PA13 - SWDIO (alternate 0). + * PA14 - SWCLK (alternate 0). + * PA15 - ROW4 + */ +#define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_PIN0) | \ + PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_INPUT(GPIOA_PIN2) | \ + PIN_MODE_INPUT(GPIOA_PIN3) | \ + PIN_MODE_INPUT(GPIOA_PIN4) | \ + PIN_MODE_INPUT(GPIOA_PIN5) | \ + PIN_MODE_INPUT(GPIOA_PIN6) | \ + PIN_MODE_INPUT(GPIOA_PIN7) | \ + PIN_MODE_INPUT(GPIOA_PIN8) | \ + PIN_MODE_INPUT(GPIOA_PIN9) | \ + PIN_MODE_INPUT(GPIOA_PIN10) | \ + PIN_MODE_ALTERNATE(GPIOA_USB_DM) | \ + PIN_MODE_ALTERNATE(GPIOA_USB_DP) | \ + PIN_MODE_ALTERNATE(GPIOA_SWDIO) | \ + PIN_MODE_ALTERNATE(GPIOA_SWCLK) | \ + PIN_MODE_INPUT(GPIOA_PIN15)) +#define VAL_GPIOA_OTYPER (PIN_OTYPE_PUSHPULL(GPIOA_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOA_USB_DM) | \ + PIN_OTYPE_PUSHPULL(GPIOA_USB_DP) | \ + PIN_OTYPE_PUSHPULL(GPIOA_SWDIO) | \ + PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN15)) +#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOA_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN10) | \ + PIN_OSPEED_HIGH(GPIOA_USB_DM) | \ + PIN_OSPEED_VERYLOW(GPIOA_USB_DP) | \ + PIN_OSPEED_HIGH(GPIOA_SWDIO) | \ + PIN_OSPEED_HIGH(GPIOA_SWCLK) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN15)) +#define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN4) | \ + PIN_PUPDR_FLOATING(GPIOA_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN6) | \ + PIN_PUPDR_FLOATING(GPIOA_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN10) | \ + PIN_PUPDR_FLOATING(GPIOA_USB_DM) | \ + PIN_PUPDR_FLOATING(GPIOA_USB_DP) | \ + PIN_PUPDR_PULLUP(GPIOA_SWDIO) | \ + PIN_PUPDR_PULLDOWN(GPIOA_SWCLK) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN15)) +#define VAL_GPIOA_ODR (PIN_ODR_HIGH(GPIOA_PIN0) | \ + PIN_ODR_HIGH(GPIOA_PIN1) | \ + PIN_ODR_HIGH(GPIOA_PIN2) | \ + PIN_ODR_HIGH(GPIOA_PIN3) | \ + PIN_ODR_HIGH(GPIOA_PIN4) | \ + PIN_ODR_HIGH(GPIOA_PIN5) | \ + PIN_ODR_HIGH(GPIOA_PIN6) | \ + PIN_ODR_HIGH(GPIOA_PIN7) | \ + PIN_ODR_HIGH(GPIOA_PIN8) | \ + PIN_ODR_HIGH(GPIOA_PIN9) | \ + PIN_ODR_HIGH(GPIOA_PIN10) | \ + PIN_ODR_HIGH(GPIOA_USB_DM) | \ + PIN_ODR_HIGH(GPIOA_USB_DP) | \ + PIN_ODR_HIGH(GPIOA_SWDIO) | \ + PIN_ODR_HIGH(GPIOA_SWCLK) | \ + PIN_ODR_HIGH(GPIOA_PIN15)) +#define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PIN0, 0) | \ + PIN_AFIO_AF(GPIOA_PIN1, 0) | \ + PIN_AFIO_AF(GPIOA_PIN2, 0) | \ + PIN_AFIO_AF(GPIOA_PIN3, 0) | \ + PIN_AFIO_AF(GPIOA_PIN4, 0) | \ + PIN_AFIO_AF(GPIOA_PIN5, 5) | \ + PIN_AFIO_AF(GPIOA_PIN6, 5) | \ + PIN_AFIO_AF(GPIOA_PIN7, 5)) +#define VAL_GPIOA_AFRH (PIN_AFIO_AF(GPIOA_PIN8, 0) | \ + PIN_AFIO_AF(GPIOA_PIN9, 0) | \ + PIN_AFIO_AF(GPIOA_PIN10, 0) | \ + PIN_AFIO_AF(GPIOA_USB_DM, 14) | \ + PIN_AFIO_AF(GPIOA_USB_DP, 14) | \ + PIN_AFIO_AF(GPIOA_SWDIO, 0) | \ + PIN_AFIO_AF(GPIOA_SWCLK, 0) | \ + PIN_AFIO_AF(GPIOA_PIN15, 0)) + +/* + * GPIOB setup: + * + * PB0 - PIN0 (input pullup). + * PB1 - PIN1 (input pullup). + * PB2 - PIN2 (input pullup). + * PB3 - PIN3 (alternate 0). + * PB4 - PIN4 (input pullup). + * PB5 - PIN5 (input pullup). + * PB6 - PIN6 LSM303DLHC_SCL (alternate 4). + * PB7 - PIN7 LSM303DLHC_SDA (alternate 4). + * PB8 - PIN8 (input pullup). + * PB9 - PIN9 (input pullup). + * PB10 - PIN10 (input pullup). + * PB11 - PIN11 (input pullup). + * PB12 - PIN12 (input pullup). + * PB13 - PIN13 (input pullup). + * PB14 - PIN14 (input pullup). + * PB15 - PIN15 (input pullup). + */ +#define VAL_GPIOB_MODER (PIN_MODE_INPUT(GPIOB_PIN0) | \ + PIN_MODE_INPUT(GPIOB_PIN1) | \ + PIN_MODE_INPUT(GPIOB_PIN2) | \ + PIN_MODE_ALTERNATE(GPIOB_PIN3) | \ + PIN_MODE_INPUT(GPIOB_PIN4) | \ + PIN_MODE_INPUT(GPIOB_PIN5) | \ + PIN_MODE_ALTERNATE(GPIOB_PIN6) | \ + PIN_MODE_OUTPUT(GPIOB_PIN7) | \ + PIN_MODE_INPUT(GPIOB_PIN8) | \ + PIN_MODE_INPUT(GPIOB_PIN9) | \ + PIN_MODE_INPUT(GPIOB_PIN10) | \ + PIN_MODE_INPUT(GPIOB_PIN11) | \ + PIN_MODE_INPUT(GPIOB_PIN12) | \ + PIN_MODE_INPUT(GPIOB_PIN13) | \ + PIN_MODE_INPUT(GPIOB_PIN14) | \ + PIN_MODE_INPUT(GPIOB_PIN15)) +#define VAL_GPIOB_OTYPER (PIN_OTYPE_PUSHPULL(GPIOB_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN5) | \ + PIN_OTYPE_OPENDRAIN(GPIOB_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN15)) +#define VAL_GPIOB_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOB_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN2) | \ + PIN_OSPEED_HIGH(GPIOB_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN5) | \ + PIN_OSPEED_HIGH(GPIOB_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN15)) +#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLUP(GPIOB_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN2) | \ + PIN_PUPDR_FLOATING(GPIOB_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN5) | \ + PIN_PUPDR_FLOATING(GPIOB_PIN6) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN15)) +#define VAL_GPIOB_ODR (PIN_ODR_HIGH(GPIOB_PIN0) | \ + PIN_ODR_HIGH(GPIOB_PIN1) | \ + PIN_ODR_HIGH(GPIOB_PIN2) | \ + PIN_ODR_HIGH(GPIOB_PIN3) | \ + PIN_ODR_HIGH(GPIOB_PIN4) | \ + PIN_ODR_HIGH(GPIOB_PIN5) | \ + PIN_ODR_HIGH(GPIOB_PIN6) | \ + PIN_ODR_LOW(GPIOB_PIN7) | \ + PIN_ODR_HIGH(GPIOB_PIN8) | \ + PIN_ODR_HIGH(GPIOB_PIN9) | \ + PIN_ODR_HIGH(GPIOB_PIN10) | \ + PIN_ODR_HIGH(GPIOB_PIN11) | \ + PIN_ODR_HIGH(GPIOB_PIN12) | \ + PIN_ODR_HIGH(GPIOB_PIN13) | \ + PIN_ODR_HIGH(GPIOB_PIN14) | \ + PIN_ODR_HIGH(GPIOB_PIN15)) +#define VAL_GPIOB_AFRL (PIN_AFIO_AF(GPIOB_PIN0, 0) | \ + PIN_AFIO_AF(GPIOB_PIN1, 0) | \ + PIN_AFIO_AF(GPIOB_PIN2, 0) | \ + PIN_AFIO_AF(GPIOB_PIN3, 0) | \ + PIN_AFIO_AF(GPIOB_PIN4, 0) | \ + PIN_AFIO_AF(GPIOB_PIN5, 0) | \ + PIN_AFIO_AF(GPIOB_PIN6, 4) | \ + PIN_AFIO_AF(GPIOB_PIN7, 0)) +#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_PIN8, 0) | \ + PIN_AFIO_AF(GPIOB_PIN9, 0) | \ + PIN_AFIO_AF(GPIOB_PIN10, 0) | \ + PIN_AFIO_AF(GPIOB_PIN11, 0) | \ + PIN_AFIO_AF(GPIOB_PIN12, 0) | \ + PIN_AFIO_AF(GPIOB_PIN13, 0) | \ + PIN_AFIO_AF(GPIOB_PIN14, 0) | \ + PIN_AFIO_AF(GPIOB_PIN15, 0)) + +/* + * GPIOC setup: + * + * PC0 - PIN0 (input pullup). + * PC1 - PIN1 (input pullup). + * PC2 - PIN2 (input pullup). + * PC3 - PIN3 (input pullup). + * PC4 - PIN4 (input pullup). + * PC5 - PIN5 (input pullup). + * PC6 - PIN6 (input pullup). + * PC7 - PIN7 (input pullup). + * PC8 - PIN8 (input pullup). + * PC9 - PIN9 (input pullup). + * PC10 - PIN10 (input pullup). + * PC11 - PIN11 (input pullup). + * PC12 - PIN12 (input pullup). + * PC13 - PIN13 (input pullup). + * PC14 - PIN14 (input floating). + * PC15 - PIN15 (input floating). + */ +#define VAL_GPIOC_MODER (PIN_MODE_INPUT(GPIOC_PIN0) | \ + PIN_MODE_INPUT(GPIOC_PIN1) | \ + PIN_MODE_INPUT(GPIOC_PIN2) | \ + PIN_MODE_INPUT(GPIOC_PIN3) | \ + PIN_MODE_INPUT(GPIOC_PIN4) | \ + PIN_MODE_INPUT(GPIOC_PIN5) | \ + PIN_MODE_INPUT(GPIOC_PIN6) | \ + PIN_MODE_INPUT(GPIOC_PIN7) | \ + PIN_MODE_INPUT(GPIOC_PIN8) | \ + PIN_MODE_INPUT(GPIOC_PIN9) | \ + PIN_MODE_INPUT(GPIOC_PIN10) | \ + PIN_MODE_INPUT(GPIOC_PIN11) | \ + PIN_MODE_INPUT(GPIOC_PIN12) | \ + PIN_MODE_INPUT(GPIOC_PIN13) | \ + PIN_MODE_INPUT(GPIOC_PIN14) | \ + PIN_MODE_INPUT(GPIOC_PIN15)) +#define VAL_GPIOC_OTYPER (PIN_OTYPE_PUSHPULL(GPIOC_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN15)) +#define VAL_GPIOC_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOC_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN13) | \ + PIN_OSPEED_HIGH(GPIOC_PIN14) | \ + PIN_OSPEED_HIGH(GPIOC_PIN15)) +#define VAL_GPIOC_PUPDR (PIN_PUPDR_PULLUP(GPIOC_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN13) | \ + PIN_PUPDR_FLOATING(GPIOC_PIN14) | \ + PIN_PUPDR_FLOATING(GPIOC_PIN15)) +#define VAL_GPIOC_ODR (PIN_ODR_HIGH(GPIOC_PIN0) | \ + PIN_ODR_HIGH(GPIOC_PIN1) | \ + PIN_ODR_HIGH(GPIOC_PIN2) | \ + PIN_ODR_HIGH(GPIOC_PIN3) | \ + PIN_ODR_HIGH(GPIOC_PIN4) | \ + PIN_ODR_HIGH(GPIOC_PIN5) | \ + PIN_ODR_HIGH(GPIOC_PIN6) | \ + PIN_ODR_HIGH(GPIOC_PIN7) | \ + PIN_ODR_HIGH(GPIOC_PIN8) | \ + PIN_ODR_HIGH(GPIOC_PIN9) | \ + PIN_ODR_HIGH(GPIOC_PIN10) | \ + PIN_ODR_HIGH(GPIOC_PIN11) | \ + PIN_ODR_HIGH(GPIOC_PIN12) | \ + PIN_ODR_HIGH(GPIOC_PIN13) | \ + PIN_ODR_HIGH(GPIOC_PIN14) | \ + PIN_ODR_HIGH(GPIOC_PIN15)) +#define VAL_GPIOC_AFRL (PIN_AFIO_AF(GPIOC_PIN0, 0) | \ + PIN_AFIO_AF(GPIOC_PIN1, 0) | \ + PIN_AFIO_AF(GPIOC_PIN2, 0) | \ + PIN_AFIO_AF(GPIOC_PIN3, 0) | \ + PIN_AFIO_AF(GPIOC_PIN4, 0) | \ + PIN_AFIO_AF(GPIOC_PIN5, 0) | \ + PIN_AFIO_AF(GPIOC_PIN6, 0) | \ + PIN_AFIO_AF(GPIOC_PIN7, 0)) +#define VAL_GPIOC_AFRH (PIN_AFIO_AF(GPIOC_PIN8, 0) | \ + PIN_AFIO_AF(GPIOC_PIN9, 0) | \ + PIN_AFIO_AF(GPIOC_PIN10, 0) | \ + PIN_AFIO_AF(GPIOC_PIN11, 0) | \ + PIN_AFIO_AF(GPIOC_PIN12, 0) | \ + PIN_AFIO_AF(GPIOC_PIN13, 0) | \ + PIN_AFIO_AF(GPIOC_PIN14, 0) | \ + PIN_AFIO_AF(GPIOC_PIN15, 0)) + +/* + * GPIOD setup: + * + * PD0 - PIN0 (input pullup). + * PD1 - PIN1 (input pullup). + * PD2 - PIN2 (input pullup). + * PD3 - PIN3 (input pullup). + * PD4 - PIN4 (input pullup). + * PD5 - PIN5 (input pullup). + * PD6 - PIN6 (input pullup). + * PD7 - PIN7 (input pullup). + * PD8 - PIN8 (input pullup). + * PD9 - PIN9 (input pullup). + * PD11 - PIN10 (input pullup). + * PD11 - PIN11 (input pullup). + * PD12 - PIN12 (input pullup). + * PD13 - PIN13 (input pullup). + * PD14 - PIN14 (input pullup). + * PD15 - PIN15 (input pullup). + */ +#define VAL_GPIOD_MODER (PIN_MODE_INPUT(GPIOD_PIN0) | \ + PIN_MODE_INPUT(GPIOD_PIN1) | \ + PIN_MODE_INPUT(GPIOD_PIN2) | \ + PIN_MODE_INPUT(GPIOD_PIN3) | \ + PIN_MODE_INPUT(GPIOD_PIN4) | \ + PIN_MODE_INPUT(GPIOD_PIN5) | \ + PIN_MODE_INPUT(GPIOD_PIN6) | \ + PIN_MODE_INPUT(GPIOD_PIN7) | \ + PIN_MODE_INPUT(GPIOD_PIN8) | \ + PIN_MODE_INPUT(GPIOD_PIN9) | \ + PIN_MODE_INPUT(GPIOD_PIN10) | \ + PIN_MODE_INPUT(GPIOD_PIN11) | \ + PIN_MODE_INPUT(GPIOD_PIN12) | \ + PIN_MODE_INPUT(GPIOD_PIN13) | \ + PIN_MODE_INPUT(GPIOD_PIN14) | \ + PIN_MODE_INPUT(GPIOD_PIN15)) +#define VAL_GPIOD_OTYPER (PIN_OTYPE_PUSHPULL(GPIOD_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN15)) +#define VAL_GPIOD_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOD_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN15)) +#define VAL_GPIOD_PUPDR (PIN_PUPDR_PULLUP(GPIOD_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN15)) +#define VAL_GPIOD_ODR (PIN_ODR_HIGH(GPIOD_PIN0) | \ + PIN_ODR_HIGH(GPIOD_PIN1) | \ + PIN_ODR_HIGH(GPIOD_PIN2) | \ + PIN_ODR_HIGH(GPIOD_PIN3) | \ + PIN_ODR_HIGH(GPIOD_PIN4) | \ + PIN_ODR_HIGH(GPIOD_PIN5) | \ + PIN_ODR_HIGH(GPIOD_PIN6) | \ + PIN_ODR_HIGH(GPIOD_PIN7) | \ + PIN_ODR_HIGH(GPIOD_PIN8) | \ + PIN_ODR_HIGH(GPIOD_PIN9) | \ + PIN_ODR_HIGH(GPIOD_PIN10) | \ + PIN_ODR_HIGH(GPIOD_PIN11) | \ + PIN_ODR_HIGH(GPIOD_PIN12) | \ + PIN_ODR_HIGH(GPIOD_PIN13) | \ + PIN_ODR_HIGH(GPIOD_PIN14) | \ + PIN_ODR_HIGH(GPIOD_PIN15)) +#define VAL_GPIOD_AFRL (PIN_AFIO_AF(GPIOD_PIN0, 0) | \ + PIN_AFIO_AF(GPIOD_PIN1, 0) | \ + PIN_AFIO_AF(GPIOD_PIN2, 0) | \ + PIN_AFIO_AF(GPIOD_PIN3, 0) | \ + PIN_AFIO_AF(GPIOD_PIN4, 0) | \ + PIN_AFIO_AF(GPIOD_PIN5, 0) | \ + PIN_AFIO_AF(GPIOD_PIN6, 0) | \ + PIN_AFIO_AF(GPIOD_PIN7, 0)) +#define VAL_GPIOD_AFRH (PIN_AFIO_AF(GPIOD_PIN8, 0) | \ + PIN_AFIO_AF(GPIOD_PIN9, 0) | \ + PIN_AFIO_AF(GPIOD_PIN10, 0) | \ + PIN_AFIO_AF(GPIOD_PIN11, 0) | \ + PIN_AFIO_AF(GPIOD_PIN12, 0) | \ + PIN_AFIO_AF(GPIOD_PIN13, 0) | \ + PIN_AFIO_AF(GPIOD_PIN14, 0) | \ + PIN_AFIO_AF(GPIOD_PIN15, 0)) + +/* + * GPIOE setup: + * + * PE0 - PIN0 (input pullup). + * PE1 - PIN1 (input pullup). + * PE2 - PIN2 (input pullup). + * PE3 - PIN3 L3GD20_CS (output pushpull maximum). + * PE4 - PIN4 (input pullup). + * PE5 - PIN5 (input pullup). + * PE6 - PIN6 (input pullup). + * PE7 - PIN7 (input pullup). + * PE8 - PIN8 (output pushpull maximum). + * PE9 - PIN9 (output pushpull maximum). + * PE10 - PIN10 (output pushpull maximum). + * PE11 - PIN11 (output pushpull maximum). + * PE12 - PIN12 (output pushpull maximum). + * PE13 - PIN13 (output pushpull maximum). + * PE14 - PIN14 (output pushpull maximum). + * PE15 - PIN15 (output pushpull maximum). + */ +#define VAL_GPIOE_MODER (PIN_MODE_INPUT(GPIOE_PIN0) | \ + PIN_MODE_INPUT(GPIOE_PIN1) | \ + PIN_MODE_INPUT(GPIOE_PIN2) |\ + PIN_MODE_OUTPUT(GPIOE_PIN3) | \ + PIN_MODE_INPUT(GPIOE_PIN4) |\ + PIN_MODE_INPUT(GPIOE_PIN5) |\ + PIN_MODE_INPUT(GPIOE_PIN6) | \ + PIN_MODE_INPUT(GPIOE_PIN7) | \ + PIN_MODE_OUTPUT(GPIOE_PIN8) | \ + PIN_MODE_OUTPUT(GPIOE_PIN9) | \ + PIN_MODE_OUTPUT(GPIOE_PIN10) | \ + PIN_MODE_OUTPUT(GPIOE_PIN11) | \ + PIN_MODE_OUTPUT(GPIOE_PIN12) | \ + PIN_MODE_OUTPUT(GPIOE_PIN13) | \ + PIN_MODE_OUTPUT(GPIOE_PIN14) | \ + PIN_MODE_OUTPUT(GPIOE_PIN15)) +#define VAL_GPIOE_OTYPER (PIN_OTYPE_PUSHPULL(GPIOE_PIN0) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN1) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN2) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN4) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN5) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN10) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN14) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN15)) +#define VAL_GPIOE_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOE_PIN0) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN1) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN2) |\ + PIN_OSPEED_HIGH(GPIOE_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOE_PIN4) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN5) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOE_PIN7) | \ + PIN_OSPEED_HIGH(GPIOE_PIN8) | \ + PIN_OSPEED_HIGH(GPIOE_PIN9) | \ + PIN_OSPEED_HIGH(GPIOE_PIN10) | \ + PIN_OSPEED_HIGH(GPIOE_PIN11) | \ + PIN_OSPEED_HIGH(GPIOE_PIN12) | \ + PIN_OSPEED_HIGH(GPIOE_PIN13) | \ + PIN_OSPEED_HIGH(GPIOE_PIN14) | \ + PIN_OSPEED_HIGH(GPIOE_PIN15)) +#define VAL_GPIOE_PUPDR (PIN_PUPDR_PULLUP(GPIOE_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN2) |\ + PIN_PUPDR_FLOATING(GPIOE_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN4) |\ + PIN_PUPDR_PULLUP(GPIOE_PIN5) |\ + PIN_PUPDR_PULLUP(GPIOE_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN10) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN12) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN13) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN14) |\ + PIN_PUPDR_FLOATING(GPIOE_PIN15)) +#define VAL_GPIOE_ODR (PIN_ODR_HIGH(GPIOE_PIN0) | \ + PIN_ODR_HIGH(GPIOE_PIN1) | \ + PIN_ODR_HIGH(GPIOE_PIN2) | \ + PIN_ODR_HIGH(GPIOE_PIN3) | \ + PIN_ODR_HIGH(GPIOE_PIN4) | \ + PIN_ODR_HIGH(GPIOE_PIN5) | \ + PIN_ODR_HIGH(GPIOE_PIN6) | \ + PIN_ODR_HIGH(GPIOE_PIN7) | \ + PIN_ODR_LOW(GPIOE_PIN8) | \ + PIN_ODR_LOW(GPIOE_PIN9) | \ + PIN_ODR_LOW(GPIOE_PIN10) | \ + PIN_ODR_LOW(GPIOE_PIN11) | \ + PIN_ODR_LOW(GPIOE_PIN12) | \ + PIN_ODR_LOW(GPIOE_PIN13) | \ + PIN_ODR_LOW(GPIOE_PIN14) | \ + PIN_ODR_LOW(GPIOE_PIN15)) +#define VAL_GPIOE_AFRL (PIN_AFIO_AF(GPIOE_PIN0, 0) | \ + PIN_AFIO_AF(GPIOE_PIN1, 0) | \ + PIN_AFIO_AF(GPIOE_PIN2, 0) |\ + PIN_AFIO_AF(GPIOE_PIN3, 0) | \ + PIN_AFIO_AF(GPIOE_PIN4, 0) |\ + PIN_AFIO_AF(GPIOE_PIN5, 0) |\ + PIN_AFIO_AF(GPIOE_PIN6, 0) | \ + PIN_AFIO_AF(GPIOE_PIN7, 0)) +#define VAL_GPIOE_AFRH (PIN_AFIO_AF(GPIOE_PIN8, 0) | \ + PIN_AFIO_AF(GPIOE_PIN9, 0) | \ + PIN_AFIO_AF(GPIOE_PIN10, 0) | \ + PIN_AFIO_AF(GPIOE_PIN11, 0) | \ + PIN_AFIO_AF(GPIOE_PIN12, 0) | \ + PIN_AFIO_AF(GPIOE_PIN13, 0) | \ + PIN_AFIO_AF(GPIOE_PIN14, 0) | \ + PIN_AFIO_AF(GPIOE_PIN15, 0)) + +/* + * GPIOF setup: + * + * PF0 - I2C2_SDA (input floating). + * PF1 - I2C2_SCL (input floating). + * PF2 - PIN2 (input pullup). + * PF3 - PIN3 (input pullup). + * PF4 - PIN4 (input pullup). + * PF5 - PIN5 (input pullup). + * PF6 - PIN6 (input pullup). + * PF7 - PIN7 (input pullup). + * PF8 - PIN8 (input pullup). + * PF9 - PIN9 (input pullup). + * PF10 - PIN10 (input pullup). + * PF11 - PIN11 (input pullup). + * PF12 - PIN12 (input pullup). + * PF13 - PIN13 (input pullup). + * PF14 - PIN14 (input pullup). + * PF15 - PIN15 (input pullup). + */ +#define VAL_GPIOF_MODER (PIN_MODE_INPUT(GPIOF_I2C2_SDA) | \ + PIN_MODE_INPUT(GPIOF_I2C2_SCL) | \ + PIN_MODE_INPUT(GPIOF_PIN2) | \ + PIN_MODE_INPUT(GPIOF_PIN3) | \ + PIN_MODE_INPUT(GPIOF_PIN4) | \ + PIN_MODE_INPUT(GPIOF_PIN5) | \ + PIN_MODE_INPUT(GPIOF_PIN6) | \ + PIN_MODE_INPUT(GPIOF_PIN7) | \ + PIN_MODE_INPUT(GPIOF_PIN8) | \ + PIN_MODE_INPUT(GPIOF_PIN9) | \ + PIN_MODE_INPUT(GPIOF_PIN10) | \ + PIN_MODE_INPUT(GPIOF_PIN11) | \ + PIN_MODE_INPUT(GPIOF_PIN12) | \ + PIN_MODE_INPUT(GPIOF_PIN13) | \ + PIN_MODE_INPUT(GPIOF_PIN14) | \ + PIN_MODE_INPUT(GPIOF_PIN15)) +#define VAL_GPIOF_OTYPER (PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SDA) | \ + PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SCL) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN15)) +#define VAL_GPIOF_OSPEEDR (PIN_OSPEED_HIGH(GPIOF_I2C2_SDA) | \ + PIN_OSPEED_HIGH(GPIOF_I2C2_SCL) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN15)) +#define VAL_GPIOF_PUPDR (PIN_PUPDR_FLOATING(GPIOF_I2C2_SDA) | \ + PIN_PUPDR_FLOATING(GPIOF_I2C2_SCL) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN15)) +#define VAL_GPIOF_ODR (PIN_ODR_HIGH(GPIOF_I2C2_SDA) | \ + PIN_ODR_HIGH(GPIOF_I2C2_SCL) | \ + PIN_ODR_HIGH(GPIOF_PIN2) | \ + PIN_ODR_HIGH(GPIOF_PIN3) | \ + PIN_ODR_HIGH(GPIOF_PIN4) | \ + PIN_ODR_HIGH(GPIOF_PIN5) | \ + PIN_ODR_HIGH(GPIOF_PIN6) | \ + PIN_ODR_HIGH(GPIOF_PIN7) | \ + PIN_ODR_HIGH(GPIOF_PIN8) | \ + PIN_ODR_HIGH(GPIOF_PIN9) | \ + PIN_ODR_HIGH(GPIOF_PIN10) | \ + PIN_ODR_HIGH(GPIOF_PIN11) | \ + PIN_ODR_HIGH(GPIOF_PIN12) | \ + PIN_ODR_HIGH(GPIOF_PIN13) | \ + PIN_ODR_HIGH(GPIOF_PIN14) | \ + PIN_ODR_HIGH(GPIOF_PIN15)) +#define VAL_GPIOF_AFRL (PIN_AFIO_AF(GPIOF_I2C2_SDA, 0) | \ + PIN_AFIO_AF(GPIOF_I2C2_SCL, 0) | \ + PIN_AFIO_AF(GPIOF_PIN2, 0) | \ + PIN_AFIO_AF(GPIOF_PIN3, 0) | \ + PIN_AFIO_AF(GPIOF_PIN4, 0) | \ + PIN_AFIO_AF(GPIOF_PIN5, 0) | \ + PIN_AFIO_AF(GPIOF_PIN6, 0) | \ + PIN_AFIO_AF(GPIOF_PIN7, 0)) +#define VAL_GPIOF_AFRH (PIN_AFIO_AF(GPIOF_PIN8, 0) | \ + PIN_AFIO_AF(GPIOF_PIN9, 0) | \ + PIN_AFIO_AF(GPIOF_PIN10, 0) | \ + PIN_AFIO_AF(GPIOF_PIN11, 0) | \ + PIN_AFIO_AF(GPIOF_PIN12, 0) | \ + PIN_AFIO_AF(GPIOF_PIN13, 0) | \ + PIN_AFIO_AF(GPIOF_PIN14, 0) | \ + PIN_AFIO_AF(GPIOF_PIN15, 0)) + +/* + * GPIOG setup: + * + * PG0 - PIN0 (input pullup). + * PG1 - PIN1 (input pullup). + * PG2 - PIN2 (input pullup). + * PG3 - PIN3 (input pullup). + * PG4 - PIN4 (input pullup). + * PG5 - PIN5 (input pullup). + * PG6 - PIN6 (input pullup). + * PG7 - PIN7 (input pullup). + * PG8 - PIN8 (input pullup). + * PG9 - PIN9 (input pullup). + * PG10 - PIN10 (input pullup). + * PG11 - PIN11 (input pullup). + * PG12 - PIN12 (input pullup). + * PG13 - PIN13 (input pullup). + * PG14 - PIN14 (input pullup). + * PG15 - PIN15 (input pullup). + */ +#define VAL_GPIOG_MODER (PIN_MODE_INPUT(GPIOG_PIN0) | \ + PIN_MODE_INPUT(GPIOG_PIN1) | \ + PIN_MODE_INPUT(GPIOG_PIN2) | \ + PIN_MODE_INPUT(GPIOG_PIN3) | \ + PIN_MODE_INPUT(GPIOG_PIN4) | \ + PIN_MODE_INPUT(GPIOG_PIN5) | \ + PIN_MODE_INPUT(GPIOG_PIN6) | \ + PIN_MODE_INPUT(GPIOG_PIN7) | \ + PIN_MODE_INPUT(GPIOG_PIN8) | \ + PIN_MODE_INPUT(GPIOG_PIN9) | \ + PIN_MODE_INPUT(GPIOG_PIN10) | \ + PIN_MODE_INPUT(GPIOG_PIN11) | \ + PIN_MODE_INPUT(GPIOG_PIN12) | \ + PIN_MODE_INPUT(GPIOG_PIN13) | \ + PIN_MODE_INPUT(GPIOG_PIN14) | \ + PIN_MODE_INPUT(GPIOG_PIN15)) +#define VAL_GPIOG_OTYPER (PIN_OTYPE_PUSHPULL(GPIOG_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN15)) +#define VAL_GPIOG_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOG_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN15)) +#define VAL_GPIOG_PUPDR (PIN_PUPDR_PULLUP(GPIOG_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN15)) +#define VAL_GPIOG_ODR (PIN_ODR_HIGH(GPIOG_PIN0) | \ + PIN_ODR_HIGH(GPIOG_PIN1) | \ + PIN_ODR_HIGH(GPIOG_PIN2) | \ + PIN_ODR_HIGH(GPIOG_PIN3) | \ + PIN_ODR_HIGH(GPIOG_PIN4) | \ + PIN_ODR_HIGH(GPIOG_PIN5) | \ + PIN_ODR_HIGH(GPIOG_PIN6) | \ + PIN_ODR_HIGH(GPIOG_PIN7) | \ + PIN_ODR_HIGH(GPIOG_PIN8) | \ + PIN_ODR_HIGH(GPIOG_PIN9) | \ + PIN_ODR_HIGH(GPIOG_PIN10) | \ + PIN_ODR_HIGH(GPIOG_PIN11) | \ + PIN_ODR_HIGH(GPIOG_PIN12) | \ + PIN_ODR_HIGH(GPIOG_PIN13) | \ + PIN_ODR_HIGH(GPIOG_PIN14) | \ + PIN_ODR_HIGH(GPIOG_PIN15)) +#define VAL_GPIOG_AFRL (PIN_AFIO_AF(GPIOG_PIN0, 0) | \ + PIN_AFIO_AF(GPIOG_PIN1, 0) | \ + PIN_AFIO_AF(GPIOG_PIN2, 0) | \ + PIN_AFIO_AF(GPIOG_PIN3, 0) | \ + PIN_AFIO_AF(GPIOG_PIN4, 0) | \ + PIN_AFIO_AF(GPIOG_PIN5, 0) | \ + PIN_AFIO_AF(GPIOG_PIN6, 0) | \ + PIN_AFIO_AF(GPIOG_PIN7, 0)) +#define VAL_GPIOG_AFRH (PIN_AFIO_AF(GPIOG_PIN8, 0) | \ + PIN_AFIO_AF(GPIOG_PIN9, 0) | \ + PIN_AFIO_AF(GPIOG_PIN10, 0) | \ + PIN_AFIO_AF(GPIOG_PIN11, 0) | \ + PIN_AFIO_AF(GPIOG_PIN12, 0) | \ + PIN_AFIO_AF(GPIOG_PIN13, 0) | \ + PIN_AFIO_AF(GPIOG_PIN14, 0) | \ + PIN_AFIO_AF(GPIOG_PIN15, 0)) + +/* + * GPIOH setup: + * + * PH0 - PIN0 (input pullup). + * PH1 - PIN1 (input pullup). + * PH2 - PIN2 (input pullup). + * PH3 - PIN3 (input pullup). + * PH4 - PIN4 (input pullup). + * PH5 - PIN5 (input pullup). + * PH6 - PIN6 (input pullup). + * PH7 - PIN7 (input pullup). + * PH8 - PIN8 (input pullup). + * PH9 - PIN9 (input pullup). + * PH10 - PIN10 (input pullup). + * PH11 - PIN11 (input pullup). + * PH12 - PIN12 (input pullup). + * PH13 - PIN13 (input pullup). + * PH14 - PIN14 (input pullup). + * PH15 - PIN15 (input pullup). + */ +#define VAL_GPIOH_MODER (PIN_MODE_INPUT(GPIOH_PIN0) | \ + PIN_MODE_INPUT(GPIOH_PIN1) | \ + PIN_MODE_INPUT(GPIOH_PIN2) | \ + PIN_MODE_INPUT(GPIOH_PIN3) | \ + PIN_MODE_INPUT(GPIOH_PIN4) | \ + PIN_MODE_INPUT(GPIOH_PIN5) | \ + PIN_MODE_INPUT(GPIOH_PIN6) | \ + PIN_MODE_INPUT(GPIOH_PIN7) | \ + PIN_MODE_INPUT(GPIOH_PIN8) | \ + PIN_MODE_INPUT(GPIOH_PIN9) | \ + PIN_MODE_INPUT(GPIOH_PIN10) | \ + PIN_MODE_INPUT(GPIOH_PIN11) | \ + PIN_MODE_INPUT(GPIOH_PIN12) | \ + PIN_MODE_INPUT(GPIOH_PIN13) | \ + PIN_MODE_INPUT(GPIOH_PIN14) | \ + PIN_MODE_INPUT(GPIOH_PIN15)) +#define VAL_GPIOH_OTYPER (PIN_OTYPE_PUSHPULL(GPIOH_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN15)) +#define VAL_GPIOH_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOH_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN15)) +#define VAL_GPIOH_PUPDR (PIN_PUPDR_PULLUP(GPIOH_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN15)) +#define VAL_GPIOH_ODR (PIN_ODR_HIGH(GPIOH_PIN0) | \ + PIN_ODR_HIGH(GPIOH_PIN1) | \ + PIN_ODR_HIGH(GPIOH_PIN2) | \ + PIN_ODR_HIGH(GPIOH_PIN3) | \ + PIN_ODR_HIGH(GPIOH_PIN4) | \ + PIN_ODR_HIGH(GPIOH_PIN5) | \ + PIN_ODR_HIGH(GPIOH_PIN6) | \ + PIN_ODR_HIGH(GPIOH_PIN7) | \ + PIN_ODR_HIGH(GPIOH_PIN8) | \ + PIN_ODR_HIGH(GPIOH_PIN9) | \ + PIN_ODR_HIGH(GPIOH_PIN10) | \ + PIN_ODR_HIGH(GPIOH_PIN11) | \ + PIN_ODR_HIGH(GPIOH_PIN12) | \ + PIN_ODR_HIGH(GPIOH_PIN13) | \ + PIN_ODR_HIGH(GPIOH_PIN14) | \ + PIN_ODR_HIGH(GPIOH_PIN15)) +#define VAL_GPIOH_AFRL (PIN_AFIO_AF(GPIOH_PIN0, 0) | \ + PIN_AFIO_AF(GPIOH_PIN1, 0) | \ + PIN_AFIO_AF(GPIOH_PIN2, 0) | \ + PIN_AFIO_AF(GPIOH_PIN3, 0) | \ + PIN_AFIO_AF(GPIOH_PIN4, 0) | \ + PIN_AFIO_AF(GPIOH_PIN5, 0) | \ + PIN_AFIO_AF(GPIOH_PIN6, 0) | \ + PIN_AFIO_AF(GPIOH_PIN7, 0)) +#define VAL_GPIOH_AFRH (PIN_AFIO_AF(GPIOH_PIN8, 0) | \ + PIN_AFIO_AF(GPIOH_PIN9, 0) | \ + PIN_AFIO_AF(GPIOH_PIN10, 0) | \ + PIN_AFIO_AF(GPIOH_PIN11, 0) | \ + PIN_AFIO_AF(GPIOH_PIN12, 0) | \ + PIN_AFIO_AF(GPIOH_PIN13, 0) | \ + PIN_AFIO_AF(GPIOH_PIN14, 0) | \ + PIN_AFIO_AF(GPIOH_PIN15, 0)) + + +/* + * USB bus activation macro, required by the USB driver. + */ +// #define usb_lld_connect_bus(usbp) +#define usb_lld_connect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_ALTERNATE(14))) +// #define usb_lld_connect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_INPUT) +/* + * USB bus de-activation macro, required by the USB driver. + */ +// #define usb_lld_disconnect_bus(usbp) +#define usb_lld_disconnect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_OUTPUT_PUSHPULL)); palClearPad(GPIOA, GPIOA_USB_DP) +// #define usb_lld_disconnect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 12) + +#if !defined(_FROM_ASM_) +#ifdef __cplusplus +extern "C" { +#endif + void boardInit(void); +#ifdef __cplusplus +} +#endif +#endif /* _FROM_ASM_ */ + +#endif /* _BOARD_H_ */ diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.mk b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.mk new file mode 100644 index 0000000000..43377629a3 --- /dev/null +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.mk @@ -0,0 +1,5 @@ +# List of all the board related files. +BOARDSRC = $(BOARD_PATH)/boards/GENERIC_STM32_F303XC/board.c + +# Required include directories +BOARDINC = $(BOARD_PATH)/boards/GENERIC_STM32_F303XC diff --git a/keyboards/planck/rev6/bootloader_defs.h b/keyboards/planck/rev6/bootloader_defs.h new file mode 100644 index 0000000000..3b0e9d20a6 --- /dev/null +++ b/keyboards/planck/rev6/bootloader_defs.h @@ -0,0 +1,7 @@ +/* Address for jumping to bootloader on STM32 chips. */ +/* It is chip dependent, the correct number can be looked up here: + * http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf + * This also requires a patch to chibios: + * /tmk_core/tool/chibios/ch-bootloader-jump.patch + */ +#define STM32_BOOTLOADER_ADDRESS 0x1FFFD800 diff --git a/keyboards/planck/rev6/chconf.h b/keyboards/planck/rev6/chconf.h new file mode 100644 index 0000000000..5a9b833107 --- /dev/null +++ b/keyboards/planck/rev6/chconf.h @@ -0,0 +1,520 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/chconf.h + * @brief Configuration file template. + * @details A copy of this file must be placed in each project directory, it + * contains the application specific kernel settings. + * + * @addtogroup config + * @details Kernel related settings and hooks. + * @{ + */ + +#ifndef CHCONF_H +#define CHCONF_H + +#define _CHIBIOS_RT_CONF_ + +/*===========================================================================*/ +/** + * @name System timers settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief System time counter resolution. + * @note Allowed values are 16 or 32 bits. + */ +#define CH_CFG_ST_RESOLUTION 32 + +/** + * @brief System tick frequency. + * @details Frequency of the system timer that drives the system ticks. This + * setting also defines the system tick time unit. + */ +#define CH_CFG_ST_FREQUENCY 10000 + +/** + * @brief Time delta constant for the tick-less mode. + * @note If this value is zero then the system uses the classic + * periodic tick. This value represents the minimum number + * of ticks that is safe to specify in a timeout directive. + * The value one is not valid, timeouts are rounded up to + * this value. + */ +#define CH_CFG_ST_TIMEDELTA 2 + +/** @} */ + +/*===========================================================================*/ +/** + * @name Kernel parameters and options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Round robin interval. + * @details This constant is the number of system ticks allowed for the + * threads before preemption occurs. Setting this value to zero + * disables the preemption for threads with equal priority and the + * round robin becomes cooperative. Note that higher priority + * threads can still preempt, the kernel is always preemptive. + * @note Disabling the round robin preemption makes the kernel more compact + * and generally faster. + * @note The round robin preemption is not supported in tickless mode and + * must be set to zero in that case. + */ +#define CH_CFG_TIME_QUANTUM 0 + +/** + * @brief Managed RAM size. + * @details Size of the RAM area to be managed by the OS. If set to zero + * then the whole available RAM is used. The core memory is made + * available to the heap allocator and/or can be used directly through + * the simplified core memory allocator. + * + * @note In order to let the OS manage the whole RAM the linker script must + * provide the @p __heap_base__ and @p __heap_end__ symbols. + * @note Requires @p CH_CFG_USE_MEMCORE. + */ +#define CH_CFG_MEMCORE_SIZE 0 + +/** + * @brief Idle thread automatic spawn suppression. + * @details When this option is activated the function @p chSysInit() + * does not spawn the idle thread. The application @p main() + * function becomes the idle thread and must implement an + * infinite loop. + */ +#define CH_CFG_NO_IDLE_THREAD FALSE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Performance options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief OS optimization. + * @details If enabled then time efficient rather than space efficient code + * is used when two possible implementations exist. + * + * @note This is not related to the compiler optimization options. + * @note The default is @p TRUE. + */ +#define CH_CFG_OPTIMIZE_SPEED TRUE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Subsystem options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Time Measurement APIs. + * @details If enabled then the time measurement APIs are included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_TM TRUE + +/** + * @brief Threads registry APIs. + * @details If enabled then the registry APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_REGISTRY TRUE + +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + +/** + * @brief Semaphores APIs. + * @details If enabled then the Semaphores APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_SEMAPHORES TRUE + +/** + * @brief Semaphores queuing mode. + * @details If enabled then the threads are enqueued on semaphores by + * priority rather than in FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special + * requirements. + * @note Requires @p CH_CFG_USE_SEMAPHORES. + */ +#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE + +/** + * @brief Mutexes APIs. + * @details If enabled then the mutexes APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MUTEXES TRUE + +/** + * @brief Enables recursive behavior on mutexes. + * @note Recursive mutexes are heavier and have an increased + * memory footprint. + * + * @note The default is @p FALSE. + * @note Requires @p CH_CFG_USE_MUTEXES. + */ +#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE + +/** + * @brief Conditional Variables APIs. + * @details If enabled then the conditional variables APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_MUTEXES. + */ +#define CH_CFG_USE_CONDVARS TRUE + +/** + * @brief Conditional Variables APIs with timeout. + * @details If enabled then the conditional variables APIs with timeout + * specification are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_CONDVARS. + */ +#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE + +/** + * @brief Events Flags APIs. + * @details If enabled then the event flags APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_EVENTS TRUE + +/** + * @brief Events Flags APIs with timeout. + * @details If enabled then the events APIs with timeout specification + * are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_EVENTS. + */ +#define CH_CFG_USE_EVENTS_TIMEOUT TRUE + +/** + * @brief Synchronous Messages APIs. + * @details If enabled then the synchronous messages APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MESSAGES TRUE + +/** + * @brief Synchronous Messages queuing mode. + * @details If enabled then messages are served by priority rather than in + * FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special + * requirements. + * @note Requires @p CH_CFG_USE_MESSAGES. + */ +#define CH_CFG_USE_MESSAGES_PRIORITY TRUE + +/** + * @brief Mailboxes APIs. + * @details If enabled then the asynchronous messages (mailboxes) APIs are + * included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_SEMAPHORES. + */ +#define CH_CFG_USE_MAILBOXES TRUE + +/** + * @brief Core Memory Manager APIs. + * @details If enabled then the core memory manager APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MEMCORE TRUE + +/** + * @brief Heap Allocator APIs. + * @details If enabled then the memory heap allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or + * @p CH_CFG_USE_SEMAPHORES. + * @note Mutexes are recommended. + */ +#define CH_CFG_USE_HEAP TRUE + +/** + * @brief Memory Pools Allocator APIs. + * @details If enabled then the memory pools allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MEMPOOLS TRUE + +/** + * @brief Dynamic Threads APIs. + * @details If enabled then the dynamic threads creation APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_WAITEXIT. + * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS. + */ +#define CH_CFG_USE_DYNAMIC TRUE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Debug options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Debug option, kernel statistics. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_STATISTICS FALSE + +/** + * @brief Debug option, system state check. + * @details If enabled the correct call protocol for system APIs is checked + * at runtime. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_SYSTEM_STATE_CHECK FALSE + +/** + * @brief Debug option, parameters checks. + * @details If enabled then the checks on the API functions input + * parameters are activated. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_ENABLE_CHECKS FALSE + +/** + * @brief Debug option, consistency checks. + * @details If enabled then all the assertions in the kernel code are + * activated. This includes consistency checks inside the kernel, + * runtime anomalies and port-defined checks. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_ENABLE_ASSERTS FALSE + +/** + * @brief Debug option, trace buffer. + * @details If enabled then the trace buffer is activated. + * + * @note The default is @p CH_DBG_TRACE_MASK_DISABLED. + */ +#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED + +/** + * @brief Trace buffer entries. + * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is + * different from @p CH_DBG_TRACE_MASK_DISABLED. + */ +#define CH_DBG_TRACE_BUFFER_SIZE 128 + +/** + * @brief Debug option, stack checks. + * @details If enabled then a runtime stack check is performed. + * + * @note The default is @p FALSE. + * @note The stack check is performed in a architecture/port dependent way. + * It may not be implemented or some ports. + * @note The default failure mode is to halt the system with the global + * @p panic_msg variable set to @p NULL. + */ +#define CH_DBG_ENABLE_STACK_CHECK TRUE + +/** + * @brief Debug option, stacks initialization. + * @details If enabled then the threads working area is filled with a byte + * value when a thread is created. This can be useful for the + * runtime measurement of the used stack. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_FILL_THREADS FALSE + +/** + * @brief Debug option, threads profiling. + * @details If enabled then a field is added to the @p thread_t structure that + * counts the system ticks occurred while executing the thread. + * + * @note The default is @p FALSE. + * @note This debug option is not currently compatible with the + * tickless mode. + */ +#define CH_DBG_THREADS_PROFILING FALSE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Kernel hooks + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Threads descriptor structure extension. + * @details User fields added to the end of the @p thread_t structure. + */ +#define CH_CFG_THREAD_EXTRA_FIELDS \ + /* Add threads custom fields here.*/ + +/** + * @brief Threads initialization hook. + * @details User initialization code added to the @p chThdInit() API. + * + * @note It is invoked from within @p chThdInit() and implicitly from all + * the threads creation APIs. + */ +#define CH_CFG_THREAD_INIT_HOOK(tp) { \ + /* Add threads initialization code here.*/ \ +} + +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) { \ + /* Add threads finalization code here.*/ \ +} + +/** + * @brief Context switch hook. + * @details This hook is invoked just before switching between threads. + */ +#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \ + /* Context switch code here.*/ \ +} + +/** + * @brief ISR enter hook. + */ +#define CH_CFG_IRQ_PROLOGUE_HOOK() { \ + /* IRQ prologue code here.*/ \ +} + +/** + * @brief ISR exit hook. + */ +#define CH_CFG_IRQ_EPILOGUE_HOOK() { \ + /* IRQ epilogue code here.*/ \ +} + +/** + * @brief Idle thread enter hook. + * @note This hook is invoked within a critical zone, no OS functions + * should be invoked from here. + * @note This macro can be used to activate a power saving mode. + */ +#define CH_CFG_IDLE_ENTER_HOOK() { \ + /* Idle-enter code here.*/ \ +} + +/** + * @brief Idle thread leave hook. + * @note This hook is invoked within a critical zone, no OS functions + * should be invoked from here. + * @note This macro can be used to deactivate a power saving mode. + */ +#define CH_CFG_IDLE_LEAVE_HOOK() { \ + /* Idle-leave code here.*/ \ +} + +/** + * @brief Idle Loop hook. + * @details This hook is continuously invoked by the idle thread loop. + */ +#define CH_CFG_IDLE_LOOP_HOOK() { \ + /* Idle loop code here.*/ \ +} + +/** + * @brief System tick event hook. + * @details This hook is invoked in the system tick handler immediately + * after processing the virtual timers queue. + */ +#define CH_CFG_SYSTEM_TICK_HOOK() { \ + /* System tick event code here.*/ \ +} + +/** + * @brief System halt hook. + * @details This hook is invoked in case to a system halting error before + * the system is halted. + */ +#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ + /* System halt code here.*/ \ +} + +/** + * @brief Trace hook. + * @details This hook is invoked each time a new record is written in the + * trace buffer. + */ +#define CH_CFG_TRACE_HOOK(tep) { \ + /* Trace code here.*/ \ +} + +/** @} */ + +/*===========================================================================*/ +/* Port-specific settings (override port settings defaulted in chcore.h). */ +/*===========================================================================*/ + +#endif /* CHCONF_H */ + +/** @} */ diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h new file mode 100644 index 0000000000..05d3ed49ef --- /dev/null +++ b/keyboards/planck/rev6/config.h @@ -0,0 +1,124 @@ +/* + * Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef REV6_CONFIG_H +#define REV6_CONFIG_H + +/* USB Device descriptor parameter */ +#define DEVICE_VER 0x0006 + +#undef MATRIX_ROWS +#undef MATRIX_COLS +/* key matrix size */ +#define MATRIX_ROWS 8 +#define MATRIX_COLS 6 + +/* + * Keyboard Matrix Assignments + * + * Change this to how you wired your keyboard + * COLS: AVR pins used for columns, left to right + * ROWS: AVR pins used for rows, top to bottom + * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode) + * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) + * +*/ +/* Note: These are not used for arm boards. They're here purely as documentation. + * #define MATRIX_ROW_PINS { PB0, PB1, PB2, PA15, PA10 } + * #define MATRIX_COL_PINS { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 } + * #define UNUSED_PINS + */ + +/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ +#define DEBOUNCE 6 + +/* Prevent modifiers from being stuck on after layer changes. */ +#define PREVENT_STUCK_MODIFIERS + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +//#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +//#define LOCKING_RESYNC_ENABLE + +/* + * Force NKRO + * + * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved + * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the + * makefile for this to work.) + * + * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N) + * until the next keyboard reset. + * + * NKRO may prevent your keystrokes from being detected in the BIOS, but it is + * fully operational during normal computer usage. + * + * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N) + * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by + * bootmagic, NKRO mode will always be enabled until it is toggled again during a + * power-up. + * + */ +//#define FORCE_NKRO + +/* key combination for magic key command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +//#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 1 + +#endif diff --git a/keyboards/planck/rev6/halconf.h b/keyboards/planck/rev6/halconf.h new file mode 100644 index 0000000000..8fe8e0c6f5 --- /dev/null +++ b/keyboards/planck/rev6/halconf.h @@ -0,0 +1,388 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/halconf.h + * @brief HAL configuration header. + * @details HAL configuration file, this file allows to enable or disable the + * various device drivers from your application. You may also use + * this file in order to override the device drivers default settings. + * + * @addtogroup HAL_CONF + * @{ + */ + +#ifndef HALCONF_H +#define HALCONF_H + +#include "mcuconf.h" + +/** + * @brief Enables the PAL subsystem. + */ +#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__) +#define HAL_USE_PAL TRUE +#endif + +/** + * @brief Enables the ADC subsystem. + */ +#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) +#define HAL_USE_ADC FALSE +#endif + +/** + * @brief Enables the CAN subsystem. + */ +#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__) +#define HAL_USE_CAN FALSE +#endif + +/** + * @brief Enables the DAC subsystem. + */ +#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__) +#define HAL_USE_DAC TRUE +#endif + +/** + * @brief Enables the EXT subsystem. + */ +#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__) +#define HAL_USE_EXT FALSE +#endif + +/** + * @brief Enables the GPT subsystem. + */ +#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__) +#define HAL_USE_GPT TRUE +#endif + +/** + * @brief Enables the I2C subsystem. + */ +#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) +#define HAL_USE_I2C FALSE +#endif + +/** + * @brief Enables the I2S subsystem. + */ +#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__) +#define HAL_USE_I2S FALSE +#endif + +/** + * @brief Enables the ICU subsystem. + */ +#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__) +#define HAL_USE_ICU FALSE +#endif + +/** + * @brief Enables the MAC subsystem. + */ +#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__) +#define HAL_USE_MAC FALSE +#endif + +/** + * @brief Enables the MMC_SPI subsystem. + */ +#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__) +#define HAL_USE_MMC_SPI FALSE +#endif + +/** + * @brief Enables the PWM subsystem. + */ +#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) +#define HAL_USE_PWM FALSE +#endif + +/** + * @brief Enables the QSPI subsystem. + */ +#if !defined(HAL_USE_QSPI) || defined(__DOXYGEN__) +#define HAL_USE_QSPI FALSE +#endif + +/** + * @brief Enables the RTC subsystem. + */ +#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +#define HAL_USE_RTC FALSE +#endif + +/** + * @brief Enables the SDC subsystem. + */ +#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__) +#define HAL_USE_SDC FALSE +#endif + +/** + * @brief Enables the SERIAL subsystem. + */ +#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL FALSE +#endif + +/** + * @brief Enables the SERIAL over USB subsystem. + */ +#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL_USB TRUE +#endif + +/** + * @brief Enables the SPI subsystem. + */ +#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__) +#define HAL_USE_SPI FALSE +#endif + +/** + * @brief Enables the UART subsystem. + */ +#if !defined(HAL_USE_UART) || defined(__DOXYGEN__) +#define HAL_USE_UART FALSE +#endif + +/** + * @brief Enables the USB subsystem. + */ +#if !defined(HAL_USE_USB) || defined(__DOXYGEN__) +#define HAL_USE_USB TRUE +#endif + +/** + * @brief Enables the WDG subsystem. + */ +#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__) +#define HAL_USE_WDG FALSE +#endif + +/*===========================================================================*/ +/* ADC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__) +#define ADC_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define ADC_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* CAN driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Sleep mode related APIs inclusion switch. + */ +#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__) +#define CAN_USE_SLEEP_MODE TRUE +#endif + +/*===========================================================================*/ +/* I2C driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables the mutual exclusion APIs on the I2C bus. + */ +#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define I2C_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* MAC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__) +#define MAC_USE_ZERO_COPY FALSE +#endif + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__) +#define MAC_USE_EVENTS TRUE +#endif + +/*===========================================================================*/ +/* MMC_SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + * This option is recommended also if the SPI driver does not + * use a DMA channel and heavily loads the CPU. + */ +#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__) +#define MMC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SDC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Number of initialization attempts before rejecting the card. + * @note Attempts are performed at 10mS intervals. + */ +#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__) +#define SDC_INIT_RETRY 100 +#endif + +/** + * @brief Include support for MMC cards. + * @note MMC support is not yet implemented so this option must be kept + * at @p FALSE. + */ +#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__) +#define SDC_MMC_SUPPORT FALSE +#endif + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + */ +#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__) +#define SDC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SERIAL driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Default bit rate. + * @details Configuration parameter, this is the baud rate selected for the + * default configuration. + */ +#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__) +#define SERIAL_DEFAULT_BITRATE 38400 +#endif + +/** + * @brief Serial buffers size. + * @details Configuration parameter, you can change the depth of the queue + * buffers depending on the requirements of your application. + * @note The default is 16 bytes for both the transmission and receive + * buffers. + */ +#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define SERIAL_BUFFERS_SIZE 16 +#endif + +/*===========================================================================*/ +/* SERIAL_USB driver related setting. */ +/*===========================================================================*/ + +/** + * @brief Serial over USB buffers size. + * @details Configuration parameter, the buffer size must be a multiple of + * the USB data endpoint maximum packet size. + * @note The default is 256 bytes for both the transmission and receive + * buffers. + */ +#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define SERIAL_USB_BUFFERS_SIZE 1 +#endif + +/** + * @brief Serial over USB number of buffers. + * @note The default is 2 buffers. + */ +#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__) +#define SERIAL_USB_BUFFERS_NUMBER 2 +#endif + +/*===========================================================================*/ +/* SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__) +#define SPI_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define SPI_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* UART driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__) +#define UART_USE_WAIT FALSE +#endif + +/** + * @brief Enables the @p uartAcquireBus() and @p uartReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define UART_USE_MUTUAL_EXCLUSION FALSE +#endif + +/*===========================================================================*/ +/* USB driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__) +#define USB_USE_WAIT TRUE +#endif + +#endif /* HALCONF_H */ + +/** @} */ diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c new file mode 100644 index 0000000000..098e8311d2 --- /dev/null +++ b/keyboards/planck/rev6/matrix.c @@ -0,0 +1,168 @@ +#include +#include +#include +#include "hal.h" +#include "timer.h" +#include "wait.h" +#include "printf.h" +#include "backlight.h" +#include "matrix.h" +#include "action.h" +#include "keycode.h" + +/* + * col: { B11, B10, B2, B1, A7, B0 } + * row: { A10, A9, A8, B15, C13, C14, C15, A2 } + */ +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_COLS]; +static bool debouncing = false; +static uint16_t debouncing_time = 0; +static uint8_t encoder_state = 0; +static int8_t encoder_value = 0; +static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; + +__attribute__ ((weak)) +void matrix_init_user(void) {} + +__attribute__ ((weak)) +void matrix_scan_user(void) {} + +__attribute__ ((weak)) +void matrix_init_kb(void) { + matrix_init_user(); +} + +__attribute__ ((weak)) +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +void matrix_init(void) { + printf("matrix init\n"); + //debug_matrix = true; + + palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOB, 15, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 13, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 14, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 15, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_PULLDOWN); + + palSetPadMode(GPIOB, 12, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_PULLUP); + + memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t)); + memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t)); + + encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); + + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) { + encoder_state <<= 2; + encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); + encoder_value += encoder_LUT[encoder_state & 0xF]; + if (encoder_value >= 4) { + register_code(KC_PGUP); + unregister_code(KC_PGUP); + } + if (encoder_value <= -4) { + register_code(KC_PGDN); + unregister_code(KC_PGDN); + } + encoder_value %= 4; + + for (int col = 0; col < MATRIX_COLS; col++) { + matrix_row_t data = 0; + + // strobe col { B11, B10, B2, B1, A7, B0 } + switch (col) { + case 0: palSetPad(GPIOB, 11); break; + case 1: palSetPad(GPIOB, 10); break; + case 2: palSetPad(GPIOB, 2); break; + case 3: palSetPad(GPIOB, 1); break; + case 4: palSetPad(GPIOA, 7); break; + case 5: palSetPad(GPIOB, 0); break; + } + + // need wait to settle pin state + wait_us(20); + + // read row data { A10, A9, A8, B15, C13, C14, C15, A2 } + data = ( + (palReadPad(GPIOA, 10) << 0 ) | + (palReadPad(GPIOA, 9) << 1 ) | + (palReadPad(GPIOA, 8) << 2 ) | + (palReadPad(GPIOB, 15) << 3 ) | + (palReadPad(GPIOC, 13) << 4 ) | + (palReadPad(GPIOC, 14) << 5 ) | + (palReadPad(GPIOC, 15) << 6 ) | + (palReadPad(GPIOA, 2) << 7 ) + ); + + // unstrobe col { B11, B10, B2, B1, A7, B0 } + switch (col) { + case 0: palClearPad(GPIOB, 11); break; + case 1: palClearPad(GPIOB, 10); break; + case 2: palClearPad(GPIOB, 2); break; + case 3: palClearPad(GPIOB, 1); break; + case 4: palClearPad(GPIOA, 7); break; + case 5: palClearPad(GPIOB, 0); break; + } + + if (matrix_debouncing[col] != data) { + matrix_debouncing[col] = data; + debouncing = true; + debouncing_time = timer_read(); + } + } + + if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { + for (int row = 0; row < MATRIX_ROWS; row++) { + matrix[row] = 0; + for (int col = 0; col < MATRIX_COLS; col++) { + matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col); + } + } + debouncing = false; + } + + matrix_scan_quantum(); + + return 1; +} + +bool matrix_is_on(uint8_t row, uint8_t col) { + return (matrix[row] & (1< + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "rev6.h" + +void matrix_init_kb(void) { + +} + +void matrix_scan_kb(void) { + +} diff --git a/keyboards/planck/rev6/rev6.h b/keyboards/planck/rev6/rev6.h new file mode 100644 index 0000000000..75c2904c5c --- /dev/null +++ b/keyboards/planck/rev6/rev6.h @@ -0,0 +1,21 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef REV6_H +#define REV6_H + +#include "planck.h" + +#endif diff --git a/keyboards/planck/rev6/rules.mk b/keyboards/planck/rev6/rules.mk new file mode 100644 index 0000000000..c49b528e3c --- /dev/null +++ b/keyboards/planck/rev6/rules.mk @@ -0,0 +1,55 @@ +# project specific files +SRC = matrix.c +LAYOUTS += ortho_4x12 + +## chip/board settings +# - the next two should match the directories in +# /os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) +MCU_FAMILY = STM32 +MCU_SERIES = STM32F3xx + +# Linker script to use +# - it should exist either in /os/common/ports/ARMCMx/compilers/GCC/ld/ +# or /ld/ +MCU_LDSCRIPT = STM32F303xC + +# Startup code to use +# - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ +MCU_STARTUP = stm32f3xx + +# Board: it should exist either in /os/hal/boards/ +# or /boards +BOARD = GENERIC_STM32_F303XC + +# Cortex version +MCU = cortex-m4 + +# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7 +ARMV = 7 + +USE_FPU = yes + +# Vector table for application +# 0x00000000-0x00001000 area is occupied by bootlaoder.*/ +# The CORTEX_VTOR... is needed only for MCHCK/Infinity KB +# OPT_DEFS = -DCORTEX_VTOR_INIT=0x08005000 +OPT_DEFS = + +# Options to pass to dfu-util when flashing +DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000:leave + +# Build Options +# comment out to disable the options. +# +BACKLIGHT_ENABLE = no +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration +## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.) +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = yes # Commands for debug and configuration +#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +NKRO_ENABLE = yes # USB Nkey Rollover +CUSTOM_MATRIX = yes # Custom matrix file +AUDIO_ENABLE = yes +# SERIAL_LINK_ENABLE = yes From 91efe7436579733769b53f330fcc2f1be5c4373a Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 22 Mar 2018 01:35:33 -0400 Subject: [PATCH 18/42] music map init, dip scan added --- keyboards/planck/planck.c | 7 ++++ .../rev6/boards/GENERIC_STM32_F303XC/board.h | 2 +- keyboards/planck/rev6/config.h | 6 ++- keyboards/planck/rev6/matrix.c | 35 ++++++++++++---- keyboards/planck/rev6/mcuconf.h | 2 +- keyboards/planck/rev6/rev6.c | 4 +- quantum/audio/audio_arm.c | 40 +++++++++---------- quantum/process_keycode/process_music.c | 33 +++++++++------ quantum/process_keycode/process_music.h | 5 +++ tmk_core/protocol/chibios/usb_main.c | 12 +++--- 10 files changed, 97 insertions(+), 49 deletions(-) diff --git a/keyboards/planck/planck.c b/keyboards/planck/planck.c index 9f7ffde8e9..1296f1b632 100644 --- a/keyboards/planck/planck.c +++ b/keyboards/planck/planck.c @@ -20,3 +20,10 @@ void matrix_init_kb(void) { matrix_init_user(); } + +const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS] = LAYOUT_planck_grid( + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +); \ No newline at end of file diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h index e09112eb98..7b8b826f68 100644 --- a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h @@ -297,7 +297,7 @@ PIN_PUPDR_PULLUP(GPIOA_PIN2) | \ PIN_PUPDR_PULLUP(GPIOA_PIN3) | \ PIN_PUPDR_PULLUP(GPIOA_PIN4) | \ - PIN_PUPDR_FLOATING(GPIOA_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN5) | \ PIN_PUPDR_PULLUP(GPIOA_PIN6) | \ PIN_PUPDR_FLOATING(GPIOA_PIN7) | \ PIN_PUPDR_PULLUP(GPIOA_PIN8) | \ diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h index 05d3ed49ef..831dabe62c 100644 --- a/keyboards/planck/rev6/config.h +++ b/keyboards/planck/rev6/config.h @@ -19,7 +19,7 @@ #define REV6_CONFIG_H /* USB Device descriptor parameter */ -#define DEVICE_VER 0x0006 +#define DEVICE_VER 0x0006 #undef MATRIX_ROWS #undef MATRIX_COLS @@ -43,6 +43,10 @@ * #define UNUSED_PINS */ +#define MUSIC_MAP +#undef AUDIO_VOICES +#undef C6_AUDIO + /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ #define DEBOUNCE 6 diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index 098e8311d2..007c42f0a8 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -19,10 +19,13 @@ static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_COLS]; static bool debouncing = false; static uint16_t debouncing_time = 0; + static uint8_t encoder_state = 0; static int8_t encoder_value = 0; static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; +static bool dip_switch[4] = {0, 0, 0, 0}; + __attribute__ ((weak)) void matrix_init_user(void) {} @@ -43,6 +46,19 @@ void matrix_init(void) { printf("matrix init\n"); //debug_matrix = true; + // dip switch setup + palSetPadMode(GPIOB, 14, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOB, 9, PAL_MODE_INPUT_PULLUP); + + // encoder setup + palSetPadMode(GPIOB, 12, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_PULLUP); + + encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); + + // actual matrix setup palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL); @@ -59,31 +75,36 @@ void matrix_init(void) { palSetPadMode(GPIOC, 15, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOB, 12, PAL_MODE_INPUT_PULLUP); - palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_PULLUP); memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t)); memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t)); - encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); matrix_init_quantum(); } uint8_t matrix_scan(void) { + // dip switch + dip_switch[0] = palReadPad(GPIOB, 14); + dip_switch[1] = palReadPad(GPIOA, 15); + dip_switch[2] = palReadPad(GPIOA, 10); + dip_switch[3] = palReadPad(GPIOB, 9); + + // encoder on B12 and B13 encoder_state <<= 2; encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); encoder_value += encoder_LUT[encoder_state & 0xF]; if (encoder_value >= 4) { - register_code(KC_PGUP); - unregister_code(KC_PGUP); + register_code(KC_MS_WH_UP); + unregister_code(KC_MS_WH_UP); } if (encoder_value <= -4) { - register_code(KC_PGDN); - unregister_code(KC_PGDN); + register_code(KC_MS_WH_DOWN); + unregister_code(KC_MS_WH_DOWN); } encoder_value %= 4; + // actual matrix for (int col = 0; col < MATRIX_COLS; col++) { matrix_row_t data = 0; diff --git a/keyboards/planck/rev6/mcuconf.h b/keyboards/planck/rev6/mcuconf.h index 94cb540ec9..00179f69f1 100644 --- a/keyboards/planck/rev6/mcuconf.h +++ b/keyboards/planck/rev6/mcuconf.h @@ -197,7 +197,7 @@ * SERIAL driver system settings. */ #define STM32_SERIAL_USE_USART1 FALSE -#define STM32_SERIAL_USE_USART2 FALSE +#define STM32_SERIAL_USE_USART2 TRUE #define STM32_SERIAL_USE_USART3 FALSE #define STM32_SERIAL_USE_UART4 FALSE #define STM32_SERIAL_USE_UART5 FALSE diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 16d382a3f8..650e1a194d 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -16,9 +16,9 @@ #include "rev6.h" void matrix_init_kb(void) { - + matrix_init_user(); } void matrix_scan_kb(void) { - + matrix_scan_user(); } diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index 247dc337d5..36e4c9904c 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -204,22 +204,6 @@ static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { // squarewave static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = { - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -234,7 +218,23 @@ static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047 + }; /* @@ -565,11 +565,11 @@ static void gpt_cb8(GPTDriver *gptp) { bool end_of_note = false; if (GET_CHANNEL_1_FREQ > 0) { if (!note_resting) - end_of_note = (note_position >= (note_length*16 - 1)); + end_of_note = (note_position >= (note_length*8 - 1)); else - end_of_note = (note_position >= (note_length*16)); + end_of_note = (note_position >= (note_length*8)); } else { - end_of_note = (note_position >= (note_length*16)); + end_of_note = (note_position >= (note_length*8)); } if (end_of_note) { diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index c7f41cc388..41a5bd5737 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -28,7 +28,7 @@ bool music_activated = false; bool midi_activated = false; uint8_t music_starting_note = 0x0C; int music_offset = 7; -uint8_t music_mode = MUSIC_MODE_CHROMATIC; +uint8_t music_mode = MUSIC_MODE_MAJOR; // music sequencer static bool music_sequence_recording = false; @@ -201,17 +201,26 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } } - uint8_t note; - if (music_mode == MUSIC_MODE_CHROMATIC) - note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); - else if (music_mode == MUSIC_MODE_GUITAR) - note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); - else if (music_mode == MUSIC_MODE_VIOLIN) - note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row); - else if (music_mode == MUSIC_MODE_MAJOR) - note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row); - else - note = music_starting_note; + uint8_t note = 36; + #ifdef MUSIC_MAP + if (music_mode == MUSIC_MODE_CHROMATIC) { + note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col]; + } else { + uint8_t position = music_map[record->event.key.row][record->event.key.col]; + note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12)*12; + } + #else + if (music_mode == MUSIC_MODE_CHROMATIC) + note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); + else if (music_mode == MUSIC_MODE_GUITAR) + note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); + else if (music_mode == MUSIC_MODE_VIOLIN) + note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row); + else if (music_mode == MUSIC_MODE_MAJOR) + note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row); + else + note = music_starting_note; + #endif if (record->event.pressed) { music_noteon(note); diff --git a/quantum/process_keycode/process_music.h b/quantum/process_keycode/process_music.h index 773bbfa6ba..13e5252ad5 100644 --- a/quantum/process_keycode/process_music.h +++ b/quantum/process_keycode/process_music.h @@ -29,6 +29,11 @@ enum music_modes { NUMBER_OF_MODES }; + +#ifdef MUSIC_MAP + extern const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS]; +#endif + bool process_music(uint16_t keycode, keyrecord_t *record); bool is_music_on(void); diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index f980024ab8..2ba6f20205 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -717,12 +717,14 @@ void send_mouse(report_mouse_t *report) { } osalSysUnlock(); - /* TODO: LUFA manually waits for the endpoint to become ready - * for about 10ms for mouse, kbd, system; 1ms for nkro - * is this really needed? - */ - osalSysLock(); + if(usbGetTransmitStatusI(&USB_DRIVER, MOUSE_IN_EPNUM)) { + /* Need to either suspend, or loop and call unlock/lock during + * every iteration - otherwise the system will remain locked, + * no interrupts served, so USB not going through as well. + * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */ + osalThreadSuspendS(&(&USB_DRIVER)->epc[MOUSE_IN_EPNUM]->in_state->thread); + } usbStartTransmitI(&USB_DRIVER, MOUSE_IN_EPNUM, (uint8_t *)report, sizeof(report_mouse_t)); osalSysUnlock(); } From ddee61c9bae4160326cd422934cb6ab0a5f9eced Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 25 Mar 2018 16:09:40 -0400 Subject: [PATCH 19/42] adds ws2812 driver for arm --- drivers/arm/ws2812.c | 556 ++++++++++++++++++++++++++++++++++++++ drivers/arm/ws2812.h | 94 +++++++ quantum/audio/audio_arm.c | 15 +- 3 files changed, 658 insertions(+), 7 deletions(-) create mode 100644 drivers/arm/ws2812.c create mode 100644 drivers/arm/ws2812.h diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c new file mode 100644 index 0000000000..e39c2554e5 --- /dev/null +++ b/drivers/arm/ws2812.c @@ -0,0 +1,556 @@ +/* + + WS2812B CPU and memory efficient library + + Date: 28.9.2016 + + Author: Martin Hubacek + http://www.martinhubacek.cz + @hubmartin + + Licence: MIT License + +*/ + +#include + +#include "stm32f3xx_hal.h" +#include "ws2812.h" + +extern WS2812_Struct ws2812b; + +// Define source arrays for my DMAs +uint32_t WS2812_IO_High[] = { WS2812B_PINS }; +uint32_t WS2812_IO_Low[] = {WS2812B_PINS << 16}; + +// WS2812 framebuffer - buffer for 2 LEDs - two times 24 bits +uint16_t ws2812bDmaBitBuffer[24 * 2]; + +// Gamma correction table +const uint8_t gammaTable[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, + 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, + 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, + 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, + 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, + 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, + 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, + 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, + 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, + 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, + 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, + 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; + +static void ws2812b_gpio_init(void) +{ + // WS2812B outputs + WS2812B_GPIO_CLK_ENABLE(); + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Pin = WS2812B_PINS; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(WS2812B_PORT, &GPIO_InitStruct); + + // Enable output pins for debuging to see DMA Full and Half transfer interrupts + #if defined(LED4_PORT) && defined(LED5_PORT) + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + + GPIO_InitStruct.Pin = LED4_PIN; + HAL_GPIO_Init(LED4_PORT, &GPIO_InitStruct); + GPIO_InitStruct.Pin = LED5_PIN; + HAL_GPIO_Init(LED5_PORT, &GPIO_InitStruct); + #endif +} + +TIM_HandleTypeDef Tim2Handle; +TIM_OC_InitTypeDef tim2OC1; +TIM_OC_InitTypeDef tim2OC2; + +uint32_t tim_period; +static void TIM2_init(void) +{ + // TIM2 Periph clock enable + __HAL_RCC_TIM2_CLK_ENABLE(); + + // This computation of pulse length should work ok, + // at some slower core speeds it needs some tuning. + tim_period = SystemCoreClock / 800000; // 0,125us period (10 times lower the 1,25us period to have fixed math below) + uint32_t cc1 = (10 * tim_period) / 36; + uint32_t cc2 = (10 * tim_period) / 15; + + Tim2Handle.Instance = TIM2; + + Tim2Handle.Init.Period = tim_period; + Tim2Handle.Init.RepetitionCounter = 0; + Tim2Handle.Init.Prescaler = 0; + Tim2Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + Tim2Handle.Init.CounterMode = TIM_COUNTERMODE_UP; + HAL_TIM_PWM_Init(&Tim2Handle); + + HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM2_IRQn); + + tim2OC1.OCMode = TIM_OCMODE_PWM1; + tim2OC1.OCPolarity = TIM_OCPOLARITY_HIGH; + tim2OC1.Pulse = cc1; + tim2OC1.OCNPolarity = TIM_OCNPOLARITY_HIGH; + tim2OC1.OCFastMode = TIM_OCFAST_DISABLE; + HAL_TIM_PWM_ConfigChannel(&Tim2Handle, &tim2OC1, TIM_CHANNEL_1); + + tim2OC2.OCMode = TIM_OCMODE_PWM1; + tim2OC2.OCPolarity = TIM_OCPOLARITY_HIGH; + tim2OC2.Pulse = cc2; + tim2OC2.OCNPolarity = TIM_OCNPOLARITY_HIGH; + tim2OC2.OCFastMode = TIM_OCFAST_DISABLE; + tim2OC2.OCIdleState = TIM_OCIDLESTATE_RESET; + tim2OC2.OCNIdleState = TIM_OCNIDLESTATE_RESET; + HAL_TIM_PWM_ConfigChannel(&Tim2Handle, &tim2OC2, TIM_CHANNEL_2); + + HAL_TIM_Base_Start(&Tim2Handle); + HAL_TIM_PWM_Start(&Tim2Handle, TIM_CHANNEL_1); + +} + + +DMA_HandleTypeDef dmaUpdate; +DMA_HandleTypeDef dmaCC1; +DMA_HandleTypeDef dmaCC2; +#define BUFFER_SIZE (sizeof(ws2812bDmaBitBuffer)/sizeof(uint16_t)) + +static void DMA_init(void) +{ + + // TIM2 Update event + __HAL_RCC_DMA1_CLK_ENABLE(); + dmaUpdate.Init.Direction = DMA_MEMORY_TO_PERIPH; + dmaUpdate.Init.PeriphInc = DMA_PINC_DISABLE; + dmaUpdate.Init.MemInc = DMA_MINC_DISABLE; + dmaUpdate.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; + dmaUpdate.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; + dmaUpdate.Init.Mode = DMA_CIRCULAR; + dmaUpdate.Init.Priority = DMA_PRIORITY_VERY_HIGH; + dmaUpdate.Instance = DMA1_Channel2; + //dmaUpdate.XferCpltCallback = TransferComplete; + //dmaUpdate.XferErrorCallback = TransferError; + HAL_DMA_Init(&dmaUpdate); + //HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); + //HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); + HAL_DMA_Start(&dmaUpdate, (uint32_t)WS2812_IO_High, (uint32_t)&WS2812B_PORT->BSRR, BUFFER_SIZE); + + + // TIM2 CC1 event + dmaCC1.Init.Direction = DMA_MEMORY_TO_PERIPH; + dmaCC1.Init.PeriphInc = DMA_PINC_DISABLE; + dmaCC1.Init.MemInc = DMA_MINC_ENABLE; + dmaCC1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; + dmaCC1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + dmaCC1.Init.Mode = DMA_CIRCULAR; + dmaCC1.Init.Priority = DMA_PRIORITY_VERY_HIGH; + dmaCC1.Instance = DMA1_Channel5; + //dmaUpdate.XferCpltCallback = TransferComplete; + //dmaUpdate.XferErrorCallback = TransferError; + //dmaUpdate.XferHalfCpltCallback = TransferHalf; + //HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0); + //HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); + HAL_DMA_Init(&dmaCC1); + HAL_DMA_Start(&dmaCC1, (uint32_t)ws2812bDmaBitBuffer, (uint32_t)&WS2812B_PORT->BRR, BUFFER_SIZE); + + + // TIM2 CC2 event + dmaCC2.Init.Direction = DMA_MEMORY_TO_PERIPH; + dmaCC2.Init.PeriphInc = DMA_PINC_DISABLE; + dmaCC2.Init.MemInc = DMA_MINC_DISABLE; + dmaCC2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; + dmaCC2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; + dmaCC2.Init.Mode = DMA_CIRCULAR; + dmaCC2.Init.Priority = DMA_PRIORITY_VERY_HIGH; + dmaCC2.Instance = DMA1_Channel7; + dmaCC2.XferCpltCallback = DMA_TransferCompleteHandler; + dmaCC2.XferHalfCpltCallback = DMA_TransferHalfHandler; + //dmaUpdate.XferErrorCallback = TransferError; + HAL_DMA_Init(&dmaCC2); + HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); + HAL_DMA_Start_IT(&dmaCC2, (uint32_t)WS2812_IO_Low, (uint32_t)&WS2812B_PORT->BSRR, BUFFER_SIZE); + +} + +/* +void DMA1_Channel2_IRQHandler(void) +{ + // Check the interrupt and clear flag + HAL_DMA_IRQHandler(&dmaUpdate); +} + +void DMA1_Channel5_IRQHandler(void) +{ + // Check the interrupt and clear flag + HAL_DMA_IRQHandler(&dmaCC1); +}*/ + +void DMA1_Channel7_IRQHandler(void) +{ + // Check the interrupt and clear flag + HAL_DMA_IRQHandler(&dmaCC2); +} + + + +static void loadNextFramebufferData(WS2812_BufferItem *bItem, uint32_t row) +{ + + uint32_t r = bItem->frameBufferPointer[bItem->frameBufferCounter++]; + uint32_t g = bItem->frameBufferPointer[bItem->frameBufferCounter++]; + uint32_t b = bItem->frameBufferPointer[bItem->frameBufferCounter++]; + + if(bItem->frameBufferCounter == bItem->frameBufferSize) + bItem->frameBufferCounter = 0; + + ws2812b_set_pixel(bItem->channel, row, r, g, b); +} + + +// Transmit the framebuffer +static void WS2812_sendbuf() +{ + // transmission complete flag + ws2812b.transferComplete = 0; + + uint32_t i; + + for( i = 0; i < WS2812_BUFFER_COUNT; i++ ) + { + ws2812b.item[i].frameBufferCounter = 0; + + loadNextFramebufferData(&ws2812b.item[i], 0); // ROW 0 + loadNextFramebufferData(&ws2812b.item[i], 1); // ROW 0 + } + + // clear all DMA flags + __HAL_DMA_CLEAR_FLAG(&dmaUpdate, DMA_FLAG_TC2 | DMA_FLAG_HT2 | DMA_FLAG_TE2); + __HAL_DMA_CLEAR_FLAG(&dmaCC1, DMA_FLAG_TC5 | DMA_FLAG_HT5 | DMA_FLAG_TE5); + __HAL_DMA_CLEAR_FLAG(&dmaCC2, DMA_FLAG_TC7 | DMA_FLAG_HT7 | DMA_FLAG_TE7); + + // configure the number of bytes to be transferred by the DMA controller + dmaUpdate.Instance->CNDTR = BUFFER_SIZE; + dmaCC1.Instance->CNDTR = BUFFER_SIZE; + dmaCC2.Instance->CNDTR = BUFFER_SIZE; + + // clear all TIM2 flags + __HAL_TIM_CLEAR_FLAG(&Tim2Handle, TIM_FLAG_UPDATE | TIM_FLAG_CC1 | TIM_FLAG_CC2 | TIM_FLAG_CC3 | TIM_FLAG_CC4); + + // enable DMA channels + __HAL_DMA_ENABLE(&dmaUpdate); + __HAL_DMA_ENABLE(&dmaCC1); + __HAL_DMA_ENABLE(&dmaCC2); + + // IMPORTANT: enable the TIM2 DMA requests AFTER enabling the DMA channels! + __HAL_TIM_ENABLE_DMA(&Tim2Handle, TIM_DMA_UPDATE); + __HAL_TIM_ENABLE_DMA(&Tim2Handle, TIM_DMA_CC1); + __HAL_TIM_ENABLE_DMA(&Tim2Handle, TIM_DMA_CC2); + + TIM2->CNT = tim_period-1; + + // start TIM2 + __HAL_TIM_ENABLE(&Tim2Handle); +} + + + + + +void DMA_TransferHalfHandler(DMA_HandleTypeDef *DmaHandle) +{ + #if defined(LED4_PORT) + LED4_PORT->BSRR = LED4_PIN; + #endif + + // Is this the last LED? + if(ws2812b.repeatCounter != (WS2812B_NUMBER_OF_LEDS / 2 - 1)) + { + uint32_t i; + + for( i = 0; i < WS2812_BUFFER_COUNT; i++ ) + { + loadNextFramebufferData(&ws2812b.item[i], 0); + } + + } else { + // If this is the last pixel, set the next pixel value to zeros, because + // the DMA would not stop exactly at the last bit. + ws2812b_set_pixel(0, 0, 0, 0, 0); + } + + #if defined(LED4_PORT) + LED4_PORT->BRR = LED4_PIN; + #endif +} + +void DMA_TransferCompleteHandler(DMA_HandleTypeDef *DmaHandle) +{ + #if defined(LED5_PORT) + LED5_PORT->BSRR = LED5_PIN; + #endif + + ws2812b.repeatCounter++; + + if(ws2812b.repeatCounter == WS2812B_NUMBER_OF_LEDS / 2) + { + // Transfer of all LEDs is done, disable DMA but enable tiemr update IRQ to stop the 50us pulse + ws2812b.repeatCounter = 0; + + // Enable TIM2 Update interrupt for 50us Treset signal + __HAL_TIM_ENABLE_IT(&Tim2Handle, TIM_IT_UPDATE); + // Disable DMA + __HAL_DMA_DISABLE(&dmaUpdate); + __HAL_DMA_DISABLE(&dmaCC1); + __HAL_DMA_DISABLE(&dmaCC2); + + // Disable the DMA requests + __HAL_TIM_DISABLE_DMA(&Tim2Handle, TIM_DMA_UPDATE); + __HAL_TIM_DISABLE_DMA(&Tim2Handle, TIM_DMA_CC1); + __HAL_TIM_DISABLE_DMA(&Tim2Handle, TIM_DMA_CC2); + + // Manually set outputs to low to generate 50us reset impulse + WS2812B_PORT->BSRR = WS2812_IO_Low[0]; + } else { + + // Load bitbuffer with next RGB LED values + uint32_t i; + for( i = 0; i < WS2812_BUFFER_COUNT; i++ ) + { + loadNextFramebufferData(&ws2812b.item[i], 1); + } + + } + + #if defined(LED5_PORT) + LED5_PORT->BRR = LED5_PIN; + #endif +} + + +void TIM2_IRQHandler(void) +{ + HAL_TIM_IRQHandler(&Tim2Handle); +} + +// TIM2 Interrupt Handler gets executed on every TIM2 Update if enabled +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + // I have to wait 50us to generate Treset signal + if (ws2812b.timerPeriodCounter < (uint8_t)WS2812_RESET_PERIOD) + { + // count the number of timer periods + ws2812b.timerPeriodCounter++; + } + else + { + ws2812b.timerPeriodCounter = 0; + __HAL_TIM_DISABLE(&Tim2Handle); + TIM2->CR1 = 0; // disable timer + + // disable the TIM2 Update + __HAL_TIM_DISABLE_IT(&Tim2Handle, TIM_IT_UPDATE); + // set TransferComplete flag + ws2812b.transferComplete = 1; + } + +} + + + +static void ws2812b_set_pixel(uint8_t row, uint16_t column, uint8_t red, uint8_t green, uint8_t blue) +{ + + // Apply gamma + red = gammaTable[red]; + green = gammaTable[green]; + blue = gammaTable[blue]; + + + uint32_t calcCol = (column*24); + uint32_t invRed = ~red; + uint32_t invGreen = ~green; + uint32_t invBlue = ~blue; + + +#if defined(SETPIX_1) + uint8_t i; + uint32_t calcClearRow = ~(0x01<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<> 7); + bitBand+=16; + + *bitBand = (invGreen >> 6); + bitBand+=16; + + *bitBand = (invGreen >> 5); + bitBand+=16; + + *bitBand = (invGreen >> 4); + bitBand+=16; + + *bitBand = (invGreen >> 3); + bitBand+=16; + + *bitBand = (invGreen >> 2); + bitBand+=16; + + *bitBand = (invGreen >> 1); + bitBand+=16; + + *bitBand = (invGreen >> 0); + bitBand+=16; + + // RED + *bitBand = (invRed >> 7); + bitBand+=16; + + *bitBand = (invRed >> 6); + bitBand+=16; + + *bitBand = (invRed >> 5); + bitBand+=16; + + *bitBand = (invRed >> 4); + bitBand+=16; + + *bitBand = (invRed >> 3); + bitBand+=16; + + *bitBand = (invRed >> 2); + bitBand+=16; + + *bitBand = (invRed >> 1); + bitBand+=16; + + *bitBand = (invRed >> 0); + bitBand+=16; + + // BLUE + *bitBand = (invBlue >> 7); + bitBand+=16; + + *bitBand = (invBlue >> 6); + bitBand+=16; + + *bitBand = (invBlue >> 5); + bitBand+=16; + + *bitBand = (invBlue >> 4); + bitBand+=16; + + *bitBand = (invBlue >> 3); + bitBand+=16; + + *bitBand = (invBlue >> 2); + bitBand+=16; + + *bitBand = (invBlue >> 1); + bitBand+=16; + + *bitBand = (invBlue >> 0); + bitBand+=16; + +#endif +} + + +void ws2812b_init() +{ + ws2812b_gpio_init(); + DMA_init(); + TIM2_init(); + + // Need to start the first transfer + ws2812b.transferComplete = 1; +} + + +void ws2812b_handle() +{ + if(ws2812b.startTransfer) { + ws2812b.startTransfer = 0; + WS2812_sendbuf(); + } + +} \ No newline at end of file diff --git a/drivers/arm/ws2812.h b/drivers/arm/ws2812.h new file mode 100644 index 0000000000..53a1787374 --- /dev/null +++ b/drivers/arm/ws2812.h @@ -0,0 +1,94 @@ +/* + + WS2812B CPU and memory efficient library + + Date: 28.9.2016 + + Author: Martin Hubacek + http://www.martinhubacek.cz + @hubmartin + + Licence: MIT License + +*/ + +#ifndef WS2812B_H_ +#define WS2812B_H_ +#include "ws2812.h" + +// GPIO enable command +#define WS2812B_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() +// LED output port +#define WS2812B_PORT GPIOC +// LED output pins +#define WS2812B_PINS (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3) +// How many LEDs are in the series +#define WS2812B_NUMBER_OF_LEDS 60 + +// Number of output LED strips. Each has its own buffer. +#define WS2812_BUFFER_COUNT 2 + +// Choose one of the bit-juggling setpixel implementation +// ******************************************************* +//#define SETPIX_1 // For loop, works everywhere, slow +//#define SETPIX_2 // Bit band in a loop +//#define SETPIX_3 // Like SETPIX_1 but with unrolled loop +#define SETPIX_4 // Fastest copying using bit-banding + + +// DEBUG OUTPUT +// ******************** +#define LED4_PORT GPIOC +#define LED4_PIN GPIO_PIN_10 + +#define LED5_PORT GPIOC +#define LED5_PIN GPIO_PIN_10 + + +// Public functions +// **************** +void ws2812b_init(); +void ws2812b_handle(); + +// Library structures +// ****************** +// This value sets number of periods to generate 50uS Treset signal +#define WS2812_RESET_PERIOD 12 + +typedef struct WS2812_BufferItem { + uint8_t* frameBufferPointer; + uint32_t frameBufferSize; + uint32_t frameBufferCounter; + uint8_t channel; // digital output pin/channel +} WS2812_BufferItem; + + + +typedef struct WS2812_Struct +{ + WS2812_BufferItem item[WS2812_BUFFER_COUNT]; + uint8_t transferComplete; + uint8_t startTransfer; + uint32_t timerPeriodCounter; + uint32_t repeatCounter; +} WS2812_Struct; + +WS2812_Struct ws2812b; + +// Bit band stuff +#define RAM_BASE 0x20000000 +#define RAM_BB_BASE 0x22000000 +#define Var_ResetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 0) +#define Var_SetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 1) +#define Var_GetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2))) +#define BITBAND_SRAM(address, bit) ( (__IO uint32_t *) (RAM_BB_BASE + (((uint32_t)address) - RAM_BASE) * 32 + (bit) * 4)) + +#define varSetBit(var,bit) (Var_SetBit_BB((uint32_t)&var,bit)) +#define varResetBit(var,bit) (Var_ResetBit_BB((uint32_t)&var,bit)) +#define varGetBit(var,bit) (Var_GetBit_BB((uint32_t)&var,bit)) + +static void ws2812b_set_pixel(uint8_t row, uint16_t column, uint8_t red, uint8_t green, uint8_t blue); +void DMA_TransferCompleteHandler(DMA_HandleTypeDef *DmaHandle); +void DMA_TransferHalfHandler(DMA_HandleTypeDef *DmaHandle); + +#endif /* WS2812B_H_ */ \ No newline at end of file diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index 36e4c9904c..c8856586dc 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -317,7 +317,7 @@ void audio_init() dacStart(&DACD2, &dac1cfg2); /* - * Starting GPT6 driver, it is used for triggering the DAC. + * Starting GPT6/7 driver, it is used for triggering the DAC. */ START_CHANNEL_1(); START_CHANNEL_2(); @@ -325,12 +325,8 @@ void audio_init() /* * Starting a continuous conversion. */ - dacStartConversion(&DACD1, &dacgrpcfg1, - (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE); - dacStartConversion(&DACD2, &dacgrpcfg2, - (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE); - // gptStartContinuous(&GPTD6, 2U); - + dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE); + dacStartConversion(&DACD2, &dacgrpcfg2, (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE); audio_initialized = true; @@ -469,6 +465,8 @@ static void gpt_cb8(GPTDriver *gptp) { if (GET_CHANNEL_2_FREQ != (uint16_t)freq_alt) { UPDATE_CHANNEL_2_FREQ(freq_alt); + } else { + RESTART_CHANNEL_2(); } //note_timbre; } @@ -528,6 +526,8 @@ static void gpt_cb8(GPTDriver *gptp) { if (GET_CHANNEL_1_FREQ != (uint16_t)freq) { UPDATE_CHANNEL_1_FREQ(freq); + } else { + RESTART_CHANNEL_1(); } //note_timbre; } @@ -622,6 +622,7 @@ void play_note(float freq, int vol) { if (audio_config.enable && voices < 8) { + // Cancel notes if notes are playing if (playing_notes) stop_all_notes(); From bb71a988c2d45f5d2515fc9186f15a81affd8c0f Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 3 Apr 2018 20:57:11 -0400 Subject: [PATCH 20/42] flesh out dip and encoder support --- keyboards/planck/keymaps/default/config.h | 8 ++++-- keyboards/planck/keymaps/default/keymap.c | 30 ++++++++++++++++++++++- keyboards/planck/planck.h | 20 +++++++-------- keyboards/planck/rev6/matrix.c | 30 ++++++++++++++++------- 4 files changed, 66 insertions(+), 22 deletions(-) diff --git a/keyboards/planck/keymaps/default/config.h b/keyboards/planck/keymaps/default/config.h index a1635f2bab..8b0abf976a 100644 --- a/keyboards/planck/keymaps/default/config.h +++ b/keyboards/planck/keymaps/default/config.h @@ -25,7 +25,7 @@ /* enable basic MIDI features: - MIDI notes can be sent when in Music mode is on */ - + #define MIDI_BASIC /* enable advanced MIDI features: @@ -39,4 +39,8 @@ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 2 -#endif \ No newline at end of file + +// Most tactile encoders have detents every 4 stages +#define ENCODER_RESOLUTION 4 + +#endif diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index 0bb70ca7b1..40ae7777ee 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -75,7 +75,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , - KC_SPC, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT + BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT ), /* Dvorak @@ -266,3 +266,31 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } return true; } + +void encoder_update(bool direction) { + if (direction) { + register_code(KC_PGUP); + unregister_code(KC_PGUP); + } else { + register_code(KC_PGDN); + unregister_code(KC_PGDN); + } +} + +void dip_update(uint8_t index, bool value) { + switch (index) { + case 0: + if (value) { + #ifdef AUDIO_ENABLE + PLAY_SONG(plover_song); + #endif + layer_on(_ADJUST); + } else { + #ifdef AUDIO_ENABLE + PLAY_SONG(plover_gb_song); + #endif + layer_off(_ADJUST); + } + break; + } +} diff --git a/keyboards/planck/planck.h b/keyboards/planck/planck.h index 626798912b..f0a12d9335 100644 --- a/keyboards/planck/planck.h +++ b/keyboards/planck/planck.h @@ -60,11 +60,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_1x2uR( \ @@ -77,11 +77,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_1x2uL( \ @@ -94,11 +94,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_2x2u( \ @@ -111,11 +111,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_grid( \ @@ -128,11 +128,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define KEYMAP LAYOUT_planck_grid diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index 007c42f0a8..cd025ea49e 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -9,6 +9,7 @@ #include "matrix.h" #include "action.h" #include "keycode.h" +#include /* * col: { B11, B10, B2, B1, A7, B0 } @@ -22,7 +23,7 @@ static uint16_t debouncing_time = 0; static uint8_t encoder_state = 0; static int8_t encoder_value = 0; -static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; +static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; static bool dip_switch[4] = {0, 0, 0, 0}; @@ -83,26 +84,37 @@ void matrix_init(void) { matrix_init_quantum(); } +__attribute__ ((weak)) +void dip_update(uint8_t index, bool value) { } + +__attribute__ ((weak)) +void encoder_update(bool direction) { } + +bool last_dip_switch[4] = {0}; + uint8_t matrix_scan(void) { // dip switch dip_switch[0] = palReadPad(GPIOB, 14); dip_switch[1] = palReadPad(GPIOA, 15); dip_switch[2] = palReadPad(GPIOA, 10); dip_switch[3] = palReadPad(GPIOB, 9); + for (uint8_t i = 0; i < 4; i++) { + if (last_dip_switch[i] ^ dip_switch[i]) + dip_update(i, dip_switch[i]); + } + memcpy(last_dip_switch, dip_switch, sizeof(&dip_switch)); // encoder on B12 and B13 encoder_state <<= 2; encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); encoder_value += encoder_LUT[encoder_state & 0xF]; - if (encoder_value >= 4) { - register_code(KC_MS_WH_UP); - unregister_code(KC_MS_WH_UP); + if (encoder_value >= ENCODER_RESOLUTION) { + encoder_update(1); } - if (encoder_value <= -4) { - register_code(KC_MS_WH_DOWN); - unregister_code(KC_MS_WH_DOWN); + if (encoder_value <= -ENCODER_RESOLUTION) { + encoder_update(0); } - encoder_value %= 4; + encoder_value %= ENCODER_RESOLUTION; // actual matrix for (int col = 0; col < MATRIX_COLS; col++) { @@ -186,4 +198,4 @@ void matrix_print(void) { } printf("\n"); } -} \ No newline at end of file +} From 25642c884018fd09313d4f78773ccd587c857f9d Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 3 Apr 2018 21:07:18 -0400 Subject: [PATCH 21/42] adds default encoder res --- keyboards/planck/rev6/matrix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index cd025ea49e..62d34dd24a 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -92,6 +92,10 @@ void encoder_update(bool direction) { } bool last_dip_switch[4] = {0}; +#ifndef ENCODER_RESOLUTION + #define ENCODER_RESOLUTION 4 +#undef ENCODER_RESOLUTION + uint8_t matrix_scan(void) { // dip switch dip_switch[0] = palReadPad(GPIOB, 14); From fe72bfa07022db86a0c336d61c63c2660073a61f Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 3 Apr 2018 21:10:57 -0400 Subject: [PATCH 22/42] adds default encoder res --- keyboards/planck/rev6/matrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index 62d34dd24a..36d9259eeb 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -94,7 +94,7 @@ bool last_dip_switch[4] = {0}; #ifndef ENCODER_RESOLUTION #define ENCODER_RESOLUTION 4 -#undef ENCODER_RESOLUTION +#endif uint8_t matrix_scan(void) { // dip switch From edb4460e64fdadf2adaeee703f77728b237ebadd Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 4 Apr 2018 02:29:52 -0400 Subject: [PATCH 23/42] start muse implementation --- quantum/audio/muse.c | 110 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 quantum/audio/muse.c diff --git a/quantum/audio/muse.c b/quantum/audio/muse.c new file mode 100644 index 0000000000..88dc31af8d --- /dev/null +++ b/quantum/audio/muse.c @@ -0,0 +1,110 @@ + +enum { + MUSE_OFF, + MUSE_ON, + MUSE_C_1_2, + MUSE_C1, + MUSE_C2, + MUSE_C4, + MUSE_C8, + MUSE_C3, + MUSE_C6, + MUSE_B1, + MUSE_B2, + MUSE_B3, + MUSE_B4, + MUSE_B5, + MUSE_B6, + MUSE_B7, + MUSE_B8, + MUSE_B9, + MUSE_B10, + MUSE_B11, + MUSE_B12, + MUSE_B13, + MUSE_B14, + MUSE_B15, + MUSE_B16, + MUSE_B17, + MUSE_B18, + MUSE_B19, + MUSE_B20, + MUSE_B21, + MUSE_B22, + MUSE_B23, + MUSE_B24, + MUSE_B25, + MUSE_B26, + MUSE_B27, + MUSE_B28, + MUSE_B29, + MUSE_B30, + MUSE_B31 +}; + +bool number_of_ones_to_bool[16] = { + 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 0, 1, 0, 0, 1 +}; + +uint8_t muse_interval[4] = {0}; +uint8_t muse_theme[4] = {0}; + +bool timer_1bit = 0; +uint8_t timer_2bit = 0; +uint8_t timer_2bit_counter = 0; +uint8_t timer_4bit = 0; +uint32_t timer_31bit = 0; + +bool bit_for_value(uint8_t value) { + switch (value) { + case MUSE_OFF: + return 0; + case MUSE_ON: + return 1; + case MUSE_C_1_2: + return timer_1bit; + case MUSE_C1: + return (timer_4bit & 1); + case MUSE_C2: + return (timer_4bit & 2); + case MUSE_C4: + return (timer_4bit & 4); + case MUSE_C8: + return (timer_4bit & 8); + case MUSE_C3: + return (timer_2bit & 1); + case MUSE_C6: + return (timer_2bit & 2); + default: + return timer_31bit & (1UL << (value - MUSE_B1)); + } +} + +uint8_t clock_pulse() { + + bool top = number_of_ones_to_bool[ + bit_for_value(muse_theme[0]) + + bit_for_value(muse_theme[1]) << 1 + + bit_for_value(muse_theme[2]) << 2 + + bit_for_value(muse_theme[3]) << 3 + ]; + + if (timer_1bit == 0) { + if (timer_2bit_counter == 0) { + timer_2bit = (timer_2bit + 1) % 4; + timer_2bit_counter = (timer_2bit_counter + 1) % 3; + } + timer_4bit = (timer_4bit + 1) % 16; + timer_31bit = (timer_31bit << 1) + top; + } + + timer_1bit = (timer_1bit + 1) % 2; + + return + bit_for_value(muse_interval[0]) + + bit_for_value(muse_interval[1]) << 1 + + bit_for_value(muse_interval[2]) << 2 + + bit_for_value(muse_interval[3]) << 3; + +} From e0e5efbead6ea125f3223508886dd443be3c39a9 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 4 Apr 2018 16:49:39 -0400 Subject: [PATCH 24/42] muse working with encoder as control --- keyboards/planck/keymaps/default/keymap.c | 69 ++++++++++++++-- keyboards/planck/keymaps/default/rules.mk | 1 + keyboards/planck/rev6/matrix.c | 18 ++--- quantum/audio/audio_arm.c | 97 ++++++++++++++++++++++- quantum/audio/muse.c | 59 +++++++------- quantum/audio/muse.h | 9 +++ quantum/process_keycode/process_audio.c | 4 +- quantum/process_keycode/process_audio.h | 4 +- 8 files changed, 210 insertions(+), 51 deletions(-) create mode 100644 quantum/audio/muse.h diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index 40ae7777ee..c1a7e0fe15 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -16,6 +16,7 @@ #include "planck.h" #include "action_layer.h" +#include "muse.h" extern keymap_config_t keymap_config; @@ -267,20 +268,42 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } -void encoder_update(bool direction) { - if (direction) { - register_code(KC_PGUP); - unregister_code(KC_PGUP); +bool muse_mode = false; +uint8_t last_muse_note = 0; +uint16_t muse_counter = 0; +uint8_t muse_offset = 70; +uint16_t muse_tempo = 50; + +void encoder_update(bool clockwise) { + if (muse_mode) { + if (IS_LAYER_ON(_RAISE)) { + if (clockwise) { + muse_offset++; + } else { + muse_offset--; + } + } else { + if (clockwise) { + muse_tempo+=1; + } else { + muse_tempo-=1; + } + } } else { - register_code(KC_PGDN); - unregister_code(KC_PGDN); + if (clockwise) { + register_code(KC_PGUP); + unregister_code(KC_PGUP); + } else { + register_code(KC_PGDN); + unregister_code(KC_PGDN); + } } } -void dip_update(uint8_t index, bool value) { +void dip_update(uint8_t index, bool active) { switch (index) { case 0: - if (value) { + if (active) { #ifdef AUDIO_ENABLE PLAY_SONG(plover_song); #endif @@ -292,5 +315,35 @@ void dip_update(uint8_t index, bool value) { layer_off(_ADJUST); } break; + case 1: + if (active) { + muse_mode = true; + } else { + muse_mode = false; + stop_all_notes(); + } + } +} + +void matrix_init_user(void) { + palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL); +} + +void matrix_scan_user(void) { + if (muse_mode) { + if (muse_counter == 0) { + uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()]; + if (muse_note != last_muse_note) { + stop_note(compute_freq_for_midi_note(last_muse_note)); + play_note(compute_freq_for_midi_note(muse_note), 0xF); + last_muse_note = muse_note; + } + } + if (muse_counter > (muse_tempo / 2)) { + palSetPad(GPIOB, 5); + } else { + palClearPad(GPIOB, 5); + } + muse_counter = (muse_counter + 1) % muse_tempo; } } diff --git a/keyboards/planck/keymaps/default/rules.mk b/keyboards/planck/keymaps/default/rules.mk index e69de29bb2..dcf16bef39 100644 --- a/keyboards/planck/keymaps/default/rules.mk +++ b/keyboards/planck/keymaps/default/rules.mk @@ -0,0 +1 @@ +SRC += muse.c diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index 36d9259eeb..e4ebe48acc 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -85,10 +85,10 @@ void matrix_init(void) { } __attribute__ ((weak)) -void dip_update(uint8_t index, bool value) { } +void dip_update(uint8_t index, bool active) { } __attribute__ ((weak)) -void encoder_update(bool direction) { } +void encoder_update(bool clockwise) { } bool last_dip_switch[4] = {0}; @@ -98,10 +98,10 @@ bool last_dip_switch[4] = {0}; uint8_t matrix_scan(void) { // dip switch - dip_switch[0] = palReadPad(GPIOB, 14); - dip_switch[1] = palReadPad(GPIOA, 15); - dip_switch[2] = palReadPad(GPIOA, 10); - dip_switch[3] = palReadPad(GPIOB, 9); + dip_switch[0] = !palReadPad(GPIOB, 14); + dip_switch[1] = !palReadPad(GPIOA, 15); + dip_switch[2] = !palReadPad(GPIOA, 10); + dip_switch[3] = !palReadPad(GPIOB, 9); for (uint8_t i = 0; i < 4; i++) { if (last_dip_switch[i] ^ dip_switch[i]) dip_update(i, dip_switch[i]); @@ -113,11 +113,11 @@ uint8_t matrix_scan(void) { encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); encoder_value += encoder_LUT[encoder_state & 0xF]; if (encoder_value >= ENCODER_RESOLUTION) { - encoder_update(1); - } - if (encoder_value <= -ENCODER_RESOLUTION) { encoder_update(0); } + if (encoder_value <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + encoder_update(1); + } encoder_value %= ENCODER_RESOLUTION; // actual matrix diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index c8856586dc..d38184f323 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -79,7 +79,7 @@ float startup_song[][2] = STARTUP_SONG; static void gpt_cb8(GPTDriver *gptp); -#define DAC_BUFFER_SIZE 360 +#define DAC_BUFFER_SIZE 720 #define START_CHANNEL_1() gptStart(&GPTD6, &gpt6cfg1); \ gptStartContinuous(&GPTD6, 2U) @@ -167,6 +167,39 @@ GPTConfig gpt8cfg1 = { // 1622, 1657, 1692, 1727, 1763, 1798, 1834, 1869, 1905, 1940, 1976, 2012 // }; +// static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = { +// 12, 8, 5, 3, 2, 1, 0, 1, 2, 3, 5, 8, +// 12, 16, 20, 26, 32, 38, 45, 53, 61, 70, 80, 90, +// 101, 112, 124, 136, 150, 163, 177, 192, 208, 224, 240, 257, +// 275, 293, 312, 331, 350, 371, 391, 413, 434, 457, 479, 503, +// 526, 550, 575, 600, 626, 651, 678, 705, 732, 759, 787, 816, +// 844, 873, 903, 933, 963, 993, 1024, 1055, 1086, 1118, 1150, 1182, +// 1215, 1248, 1281, 1314, 1347, 1381, 1415, 1449, 1483, 1518, 1552, 1587, +// 1622, 1657, 1692, 1727, 1763, 1798, 1834, 1869, 1905, 1940, 1976, 2012, +// 2047, 2082, 2118, 2154, 2189, 2225, 2260, 2296, 2331, 2367, 2402, 2437, +// 2472, 2507, 2542, 2576, 2611, 2645, 2679, 2713, 2747, 2780, 2813, 2846, +// 2879, 2912, 2944, 2976, 3008, 3039, 3070, 3101, 3131, 3161, 3191, 3221, +// 3250, 3278, 3307, 3335, 3362, 3389, 3416, 3443, 3468, 3494, 3519, 3544, +// 3568, 3591, 3615, 3637, 3660, 3681, 3703, 3723, 3744, 3763, 3782, 3801, +// 3819, 3837, 3854, 3870, 3886, 3902, 3917, 3931, 3944, 3958, 3970, 3982, +// 3993, 4004, 4014, 4024, 4033, 4041, 4049, 4056, 4062, 4068, 4074, 4078, +// 4082, 4086, 4089, 4091, 4092, 4093, 4094, 4093, 4092, 4091, 4089, 4086, +// 4082, 4078, 4074, 4068, 4062, 4056, 4049, 4041, 4033, 4024, 4014, 4004, +// 3993, 3982, 3970, 3958, 3944, 3931, 3917, 3902, 3886, 3870, 3854, 3837, +// 3819, 3801, 3782, 3763, 3744, 3723, 3703, 3681, 3660, 3637, 3615, 3591, +// 3568, 3544, 3519, 3494, 3468, 3443, 3416, 3389, 3362, 3335, 3307, 3278, +// 3250, 3221, 3191, 3161, 3131, 3101, 3070, 3039, 3008, 2976, 2944, 2912, +// 2879, 2846, 2813, 2780, 2747, 2713, 2679, 2645, 2611, 2576, 2542, 2507, +// 2472, 2437, 2402, 2367, 2331, 2296, 2260, 2225, 2189, 2154, 2118, 2082, +// 2047, 2012, 1976, 1940, 1905, 1869, 1834, 1798, 1763, 1727, 1692, 1657, +// 1622, 1587, 1552, 1518, 1483, 1449, 1415, 1381, 1347, 1314, 1281, 1248, +// 1215, 1182, 1150, 1118, 1086, 1055, 1024, 993, 963, 933, 903, 873, +// 844, 816, 787, 759, 732, 705, 678, 651, 626, 600, 575, 550, +// 526, 503, 479, 457, 434, 413, 391, 371, 350, 331, 312, 293, +// 275, 257, 240, 224, 208, 192, 177, 163, 150, 136, 124, 112, +// 101, 90, 80, 70, 61, 53, 45, 38, 32, 26, 20, 16 +// }; + // squarewave static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, @@ -184,7 +217,37 @@ static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -204,6 +267,22 @@ static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { // squarewave static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = { + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -233,8 +312,22 @@ static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = { 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, + 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047 - }; /* diff --git a/quantum/audio/muse.c b/quantum/audio/muse.c index 88dc31af8d..f3cb592d81 100644 --- a/quantum/audio/muse.c +++ b/quantum/audio/muse.c @@ -1,3 +1,4 @@ +#include "muse.h" enum { MUSE_OFF, @@ -47,14 +48,14 @@ bool number_of_ones_to_bool[16] = { 0, 1, 1, 0, 1, 0, 0, 1 }; -uint8_t muse_interval[4] = {0}; -uint8_t muse_theme[4] = {0}; +uint8_t muse_interval[4] = {MUSE_B7, MUSE_B19, MUSE_B3, MUSE_B28}; +uint8_t muse_theme[4] = {MUSE_B8, MUSE_B23, MUSE_B18, MUSE_B17}; -bool timer_1bit = 0; -uint8_t timer_2bit = 0; -uint8_t timer_2bit_counter = 0; -uint8_t timer_4bit = 0; -uint32_t timer_31bit = 0; +bool muse_timer_1bit = 0; +uint8_t muse_timer_2bit = 0; +uint8_t muse_timer_2bit_counter = 0; +uint8_t muse_timer_4bit = 0; +uint32_t muse_timer_31bit = 0; bool bit_for_value(uint8_t value) { switch (value) { @@ -63,48 +64,48 @@ bool bit_for_value(uint8_t value) { case MUSE_ON: return 1; case MUSE_C_1_2: - return timer_1bit; + return muse_timer_1bit; case MUSE_C1: - return (timer_4bit & 1); + return (muse_timer_4bit & 1); case MUSE_C2: - return (timer_4bit & 2); + return (muse_timer_4bit & 2); case MUSE_C4: - return (timer_4bit & 4); + return (muse_timer_4bit & 4); case MUSE_C8: - return (timer_4bit & 8); + return (muse_timer_4bit & 8); case MUSE_C3: - return (timer_2bit & 1); + return (muse_timer_2bit & 1); case MUSE_C6: - return (timer_2bit & 2); + return (muse_timer_2bit & 2); default: - return timer_31bit & (1UL << (value - MUSE_B1)); + return muse_timer_31bit & (1UL << (value - MUSE_B1)); } } -uint8_t clock_pulse() { +uint8_t muse_clock_pulse(void) { bool top = number_of_ones_to_bool[ bit_for_value(muse_theme[0]) + - bit_for_value(muse_theme[1]) << 1 + - bit_for_value(muse_theme[2]) << 2 + - bit_for_value(muse_theme[3]) << 3 + (bit_for_value(muse_theme[1]) << 1) + + (bit_for_value(muse_theme[2]) << 2) + + (bit_for_value(muse_theme[3]) << 3) ]; - if (timer_1bit == 0) { - if (timer_2bit_counter == 0) { - timer_2bit = (timer_2bit + 1) % 4; - timer_2bit_counter = (timer_2bit_counter + 1) % 3; + if (muse_timer_1bit == 0) { + if (muse_timer_2bit_counter == 0) { + muse_timer_2bit = (muse_timer_2bit + 1) % 4; } - timer_4bit = (timer_4bit + 1) % 16; - timer_31bit = (timer_31bit << 1) + top; + muse_timer_2bit_counter = (muse_timer_2bit_counter + 1) % 3; + muse_timer_4bit = (muse_timer_4bit + 1) % 16; + muse_timer_31bit = (muse_timer_31bit << 1) + top; } - timer_1bit = (timer_1bit + 1) % 2; + muse_timer_1bit = (muse_timer_1bit + 1) % 2; return bit_for_value(muse_interval[0]) + - bit_for_value(muse_interval[1]) << 1 + - bit_for_value(muse_interval[2]) << 2 + - bit_for_value(muse_interval[3]) << 3; + (bit_for_value(muse_interval[1]) << 1) + + (bit_for_value(muse_interval[2]) << 2) + + (bit_for_value(muse_interval[3]) << 3); } diff --git a/quantum/audio/muse.h b/quantum/audio/muse.h new file mode 100644 index 0000000000..6f382a7fee --- /dev/null +++ b/quantum/audio/muse.h @@ -0,0 +1,9 @@ +#ifndef MUSE_H +#define MUSE_H + +#include "quantum.h" +#include "process_audio.h" + +uint8_t muse_clock_pulse(void); + +#endif diff --git a/quantum/process_keycode/process_audio.c b/quantum/process_keycode/process_audio.c index 32057ae8dc..0a25aa5354 100644 --- a/quantum/process_keycode/process_audio.c +++ b/quantum/process_keycode/process_audio.c @@ -10,7 +10,7 @@ float voice_change_song[][2] = VOICE_CHANGE_SONG; #define PITCH_STANDARD_A 440.0f #endif -static float compute_freq_for_midi_note(uint8_t note) +float compute_freq_for_midi_note(uint8_t note) { // https://en.wikipedia.org/wiki/MIDI_tuning_standard return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A; @@ -65,4 +65,4 @@ void process_audio_all_notes_off(void) { } __attribute__ ((weak)) -void audio_on_user() {} \ No newline at end of file +void audio_on_user() {} diff --git a/quantum/process_keycode/process_audio.h b/quantum/process_keycode/process_audio.h index 7ac15b7330..3a84c3d869 100644 --- a/quantum/process_keycode/process_audio.h +++ b/quantum/process_keycode/process_audio.h @@ -1,6 +1,8 @@ #ifndef PROCESS_AUDIO_H #define PROCESS_AUDIO_H +float compute_freq_for_midi_note(uint8_t note); + bool process_audio(uint16_t keycode, keyrecord_t *record); void process_audio_noteon(uint8_t note); void process_audio_noteoff(uint8_t note); @@ -8,4 +10,4 @@ void process_audio_all_notes_off(void); void audio_on_user(void); -#endif \ No newline at end of file +#endif From df371458b3979ec3439ba1ea7a098506a11df906 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 6 Apr 2018 12:36:20 -0400 Subject: [PATCH 25/42] flip direction --- keyboards/planck/keymaps/default/keymap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index c1a7e0fe15..77f847f4c0 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -291,11 +291,11 @@ void encoder_update(bool clockwise) { } } else { if (clockwise) { - register_code(KC_PGUP); - unregister_code(KC_PGUP); - } else { register_code(KC_PGDN); unregister_code(KC_PGDN); + } else { + register_code(KC_PGUP); + unregister_code(KC_PGUP); } } } From 676080372c8218f7f6c23edd35dd8c2f51884d51 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 24 Apr 2018 11:58:36 -0400 Subject: [PATCH 26/42] try mouse wheel again --- keyboards/planck/keymaps/default/keymap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index 77f847f4c0..b523c184ed 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -291,11 +291,11 @@ void encoder_update(bool clockwise) { } } else { if (clockwise) { - register_code(KC_PGDN); - unregister_code(KC_PGDN); + register_code(KC_MS_WH_DOWN); + unregister_code(KC_MS_WH_DOWN); } else { - register_code(KC_PGUP); - unregister_code(KC_PGUP); + register_code(KC_MS_WH_UP); + unregister_code(KC_MS_WH_UP); } } } From 82146ecfc0080a3add32bf16268383a43f93cc20 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 10 May 2018 15:54:33 -0400 Subject: [PATCH 27/42] dont break other revs --- keyboards/planck/config.h | 2 - keyboards/planck/keymaps/default/keymap.c | 5 -- quantum/config_common.h | 102 +++++++++++----------- 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/keyboards/planck/config.h b/keyboards/planck/config.h index 097bacd715..452a99d746 100644 --- a/keyboards/planck/config.h +++ b/keyboards/planck/config.h @@ -18,9 +18,7 @@ along with this program. If not, see . #ifndef CONFIG_H #define CONFIG_H -#ifdef __AVR__ #include "config_common.h" -#endif /* USB Device descriptor parameter */ #define VENDOR_ID 0xFEED diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index e6ab69d43e..81bd9d7b7d 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -324,11 +324,6 @@ void matrix_scan_user(void) { last_muse_note = muse_note; } } - if (muse_counter > (muse_tempo / 2)) { - palSetPad(GPIOB, 5); - } else { - palClearPad(GPIOB, 5); - } muse_counter = (muse_counter + 1) % muse_tempo; } } diff --git a/quantum/config_common.h b/quantum/config_common.h index 4c6a702af4..f6f51b367d 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h @@ -22,56 +22,58 @@ #define ROW2COL 1 #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */ -/* I/O pins */ -#ifndef F0 - #define B0 0x30 - #define B1 0x31 - #define B2 0x32 - #define B3 0x33 - #define B4 0x34 - #define B5 0x35 - #define B6 0x36 - #define B7 0x37 - #define C0 0x60 - #define C1 0x61 - #define C2 0x62 - #define C3 0x63 - #define C4 0x64 - #define C5 0x65 - #define C6 0x66 - #define C7 0x67 - #define D0 0x90 - #define D1 0x91 - #define D2 0x92 - #define D3 0x93 - #define D4 0x94 - #define D5 0x95 - #define D6 0x96 - #define D7 0x97 - #define E0 0xC0 - #define E1 0xC1 - #define E2 0xC2 - #define E3 0xC3 - #define E4 0xC4 - #define E5 0xC5 - #define E6 0xC6 - #define E7 0xC7 - #define F0 0xF0 - #define F1 0xF1 - #define F2 0xF2 - #define F3 0xF3 - #define F4 0xF4 - #define F5 0xF5 - #define F6 0xF6 - #define F7 0xF7 - #define A0 0x00 - #define A1 0x01 - #define A2 0x02 - #define A3 0x03 - #define A4 0x04 - #define A5 0x05 - #define A6 0x06 - #define A7 0x07 +#ifdef __AVR__ + /* I/O pins */ + #ifndef F0 + #define B0 0x30 + #define B1 0x31 + #define B2 0x32 + #define B3 0x33 + #define B4 0x34 + #define B5 0x35 + #define B6 0x36 + #define B7 0x37 + #define C0 0x60 + #define C1 0x61 + #define C2 0x62 + #define C3 0x63 + #define C4 0x64 + #define C5 0x65 + #define C6 0x66 + #define C7 0x67 + #define D0 0x90 + #define D1 0x91 + #define D2 0x92 + #define D3 0x93 + #define D4 0x94 + #define D5 0x95 + #define D6 0x96 + #define D7 0x97 + #define E0 0xC0 + #define E1 0xC1 + #define E2 0xC2 + #define E3 0xC3 + #define E4 0xC4 + #define E5 0xC5 + #define E6 0xC6 + #define E7 0xC7 + #define F0 0xF0 + #define F1 0xF1 + #define F2 0xF2 + #define F3 0xF3 + #define F4 0xF4 + #define F5 0xF5 + #define F6 0xF6 + #define F7 0xF7 + #define A0 0x00 + #define A1 0x01 + #define A2 0x02 + #define A3 0x03 + #define A4 0x04 + #define A5 0x05 + #define A6 0x06 + #define A7 0x07 + #endif #endif /* USART configuration */ From 1cb72a9c59c8b424e949f52308c48aa83f3ce43c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 10 May 2018 16:17:50 -0400 Subject: [PATCH 28/42] dont break other revs --- keyboards/planck/keymaps/default/keymap.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index 81bd9d7b7d..dc431983e3 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -310,10 +310,6 @@ void dip_update(uint8_t index, bool active) { } } -void matrix_init_user(void) { - palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL); -} - void matrix_scan_user(void) { if (muse_mode) { if (muse_counter == 0) { From 9fccfc8dd5a21923ada3b2539a9eb30f8a4d1d9c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 15 May 2018 11:36:19 -0400 Subject: [PATCH 29/42] conditional autio --- keyboards/planck/keymaps/default/keymap.c | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index dc431983e3..545ca42299 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -305,23 +305,27 @@ void dip_update(uint8_t index, bool active) { muse_mode = true; } else { muse_mode = false; - stop_all_notes(); + #ifdef AUDIO_ENABLE + stop_all_notes(); + #endif } } } void matrix_scan_user(void) { - if (muse_mode) { - if (muse_counter == 0) { - uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()]; - if (muse_note != last_muse_note) { - stop_note(compute_freq_for_midi_note(last_muse_note)); - play_note(compute_freq_for_midi_note(muse_note), 0xF); - last_muse_note = muse_note; + #ifdef AUDIO_ENABLE + if (muse_mode) { + if (muse_counter == 0) { + uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()]; + if (muse_note != last_muse_note) { + stop_note(compute_freq_for_midi_note(last_muse_note)); + play_note(compute_freq_for_midi_note(muse_note), 0xF); + last_muse_note = muse_note; + } } + muse_counter = (muse_counter + 1) % muse_tempo; } - muse_counter = (muse_counter + 1) % muse_tempo; - } + #endif } bool music_mask_user(uint16_t keycode) { From 7c19e9fa04ac467cdb7b58e9ebb45cc34ba88423 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 18 May 2018 01:32:24 -0400 Subject: [PATCH 30/42] pwm ws driver (not working) --- drivers/arm/ws2812.c | 773 ++++++++++---------------------- drivers/arm/ws2812.h | 168 +++---- keyboards/planck/config.h | 2 + keyboards/planck/rev6/config.h | 5 + keyboards/planck/rev6/halconf.h | 2 +- keyboards/planck/rev6/mcuconf.h | 2 +- keyboards/planck/rev6/rev6.c | 4 + keyboards/planck/rev6/rules.mk | 1 + quantum/rgblight.c | 20 +- quantum/rgblight_types.h | 4 +- tmk_core/chibios.mk | 2 + 11 files changed, 352 insertions(+), 631 deletions(-) diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c index e39c2554e5..bab52e7531 100644 --- a/drivers/arm/ws2812.c +++ b/drivers/arm/ws2812.c @@ -1,556 +1,245 @@ -/* +/** + * @file ws2812.c + * @author Austin Glaser + * @brief WS2812 LED driver + * + * Copyright (C) 2016 Austin Glaser + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + * + * @todo Put in names and descriptions of variables which need to be defined to use this file + * + * @addtogroup WS2812 + * @{ + */ - WS2812B CPU and memory efficient library +/* --- PRIVATE DEPENDENCIES ------------------------------------------------- */ - Date: 28.9.2016 - - Author: Martin Hubacek - http://www.martinhubacek.cz - @hubmartin - - Licence: MIT License - -*/ - -#include - -#include "stm32f3xx_hal.h" +// This Driver #include "ws2812.h" -extern WS2812_Struct ws2812b; +// Standard +#include -// Define source arrays for my DMAs -uint32_t WS2812_IO_High[] = { WS2812B_PINS }; -uint32_t WS2812_IO_Low[] = {WS2812B_PINS << 16}; +// ChibiOS +#include "ch.h" +#include "hal.h" -// WS2812 framebuffer - buffer for 2 LEDs - two times 24 bits -uint16_t ws2812bDmaBitBuffer[24 * 2]; +// Application +#include "board.h" +#include "util.h" -// Gamma correction table -const uint8_t gammaTable[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, - 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, - 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, - 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, - 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, - 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, - 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, - 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, - 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, - 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, - 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, - 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, - 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, - 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; - -static void ws2812b_gpio_init(void) -{ - // WS2812B outputs - WS2812B_GPIO_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = WS2812B_PINS; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(WS2812B_PORT, &GPIO_InitStruct); - - // Enable output pins for debuging to see DMA Full and Half transfer interrupts - #if defined(LED4_PORT) && defined(LED5_PORT) - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - - GPIO_InitStruct.Pin = LED4_PIN; - HAL_GPIO_Init(LED4_PORT, &GPIO_InitStruct); - GPIO_InitStruct.Pin = LED5_PIN; - HAL_GPIO_Init(LED5_PORT, &GPIO_InitStruct); - #endif -} - -TIM_HandleTypeDef Tim2Handle; -TIM_OC_InitTypeDef tim2OC1; -TIM_OC_InitTypeDef tim2OC2; - -uint32_t tim_period; -static void TIM2_init(void) -{ - // TIM2 Periph clock enable - __HAL_RCC_TIM2_CLK_ENABLE(); - - // This computation of pulse length should work ok, - // at some slower core speeds it needs some tuning. - tim_period = SystemCoreClock / 800000; // 0,125us period (10 times lower the 1,25us period to have fixed math below) - uint32_t cc1 = (10 * tim_period) / 36; - uint32_t cc2 = (10 * tim_period) / 15; - - Tim2Handle.Instance = TIM2; - - Tim2Handle.Init.Period = tim_period; - Tim2Handle.Init.RepetitionCounter = 0; - Tim2Handle.Init.Prescaler = 0; - Tim2Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; - Tim2Handle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_PWM_Init(&Tim2Handle); - - HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(TIM2_IRQn); - - tim2OC1.OCMode = TIM_OCMODE_PWM1; - tim2OC1.OCPolarity = TIM_OCPOLARITY_HIGH; - tim2OC1.Pulse = cc1; - tim2OC1.OCNPolarity = TIM_OCNPOLARITY_HIGH; - tim2OC1.OCFastMode = TIM_OCFAST_DISABLE; - HAL_TIM_PWM_ConfigChannel(&Tim2Handle, &tim2OC1, TIM_CHANNEL_1); - - tim2OC2.OCMode = TIM_OCMODE_PWM1; - tim2OC2.OCPolarity = TIM_OCPOLARITY_HIGH; - tim2OC2.Pulse = cc2; - tim2OC2.OCNPolarity = TIM_OCNPOLARITY_HIGH; - tim2OC2.OCFastMode = TIM_OCFAST_DISABLE; - tim2OC2.OCIdleState = TIM_OCIDLESTATE_RESET; - tim2OC2.OCNIdleState = TIM_OCNIDLESTATE_RESET; - HAL_TIM_PWM_ConfigChannel(&Tim2Handle, &tim2OC2, TIM_CHANNEL_2); - - HAL_TIM_Base_Start(&Tim2Handle); - HAL_TIM_PWM_Start(&Tim2Handle, TIM_CHANNEL_1); - -} - - -DMA_HandleTypeDef dmaUpdate; -DMA_HandleTypeDef dmaCC1; -DMA_HandleTypeDef dmaCC2; -#define BUFFER_SIZE (sizeof(ws2812bDmaBitBuffer)/sizeof(uint16_t)) - -static void DMA_init(void) -{ - - // TIM2 Update event - __HAL_RCC_DMA1_CLK_ENABLE(); - dmaUpdate.Init.Direction = DMA_MEMORY_TO_PERIPH; - dmaUpdate.Init.PeriphInc = DMA_PINC_DISABLE; - dmaUpdate.Init.MemInc = DMA_MINC_DISABLE; - dmaUpdate.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; - dmaUpdate.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; - dmaUpdate.Init.Mode = DMA_CIRCULAR; - dmaUpdate.Init.Priority = DMA_PRIORITY_VERY_HIGH; - dmaUpdate.Instance = DMA1_Channel2; - //dmaUpdate.XferCpltCallback = TransferComplete; - //dmaUpdate.XferErrorCallback = TransferError; - HAL_DMA_Init(&dmaUpdate); - //HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0); - //HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn); - HAL_DMA_Start(&dmaUpdate, (uint32_t)WS2812_IO_High, (uint32_t)&WS2812B_PORT->BSRR, BUFFER_SIZE); - - - // TIM2 CC1 event - dmaCC1.Init.Direction = DMA_MEMORY_TO_PERIPH; - dmaCC1.Init.PeriphInc = DMA_PINC_DISABLE; - dmaCC1.Init.MemInc = DMA_MINC_ENABLE; - dmaCC1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; - dmaCC1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; - dmaCC1.Init.Mode = DMA_CIRCULAR; - dmaCC1.Init.Priority = DMA_PRIORITY_VERY_HIGH; - dmaCC1.Instance = DMA1_Channel5; - //dmaUpdate.XferCpltCallback = TransferComplete; - //dmaUpdate.XferErrorCallback = TransferError; - //dmaUpdate.XferHalfCpltCallback = TransferHalf; - //HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0); - //HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); - HAL_DMA_Init(&dmaCC1); - HAL_DMA_Start(&dmaCC1, (uint32_t)ws2812bDmaBitBuffer, (uint32_t)&WS2812B_PORT->BRR, BUFFER_SIZE); - - - // TIM2 CC2 event - dmaCC2.Init.Direction = DMA_MEMORY_TO_PERIPH; - dmaCC2.Init.PeriphInc = DMA_PINC_DISABLE; - dmaCC2.Init.MemInc = DMA_MINC_DISABLE; - dmaCC2.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; - dmaCC2.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; - dmaCC2.Init.Mode = DMA_CIRCULAR; - dmaCC2.Init.Priority = DMA_PRIORITY_VERY_HIGH; - dmaCC2.Instance = DMA1_Channel7; - dmaCC2.XferCpltCallback = DMA_TransferCompleteHandler; - dmaCC2.XferHalfCpltCallback = DMA_TransferHalfHandler; - //dmaUpdate.XferErrorCallback = TransferError; - HAL_DMA_Init(&dmaCC2); - HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); - HAL_DMA_Start_IT(&dmaCC2, (uint32_t)WS2812_IO_Low, (uint32_t)&WS2812B_PORT->BSRR, BUFFER_SIZE); - -} - -/* -void DMA1_Channel2_IRQHandler(void) -{ - // Check the interrupt and clear flag - HAL_DMA_IRQHandler(&dmaUpdate); -} - -void DMA1_Channel5_IRQHandler(void) -{ - // Check the interrupt and clear flag - HAL_DMA_IRQHandler(&dmaCC1); -}*/ - -void DMA1_Channel7_IRQHandler(void) -{ - // Check the interrupt and clear flag - HAL_DMA_IRQHandler(&dmaCC2); -} - - - -static void loadNextFramebufferData(WS2812_BufferItem *bItem, uint32_t row) -{ - - uint32_t r = bItem->frameBufferPointer[bItem->frameBufferCounter++]; - uint32_t g = bItem->frameBufferPointer[bItem->frameBufferCounter++]; - uint32_t b = bItem->frameBufferPointer[bItem->frameBufferCounter++]; - - if(bItem->frameBufferCounter == bItem->frameBufferSize) - bItem->frameBufferCounter = 0; - - ws2812b_set_pixel(bItem->channel, row, r, g, b); -} - - -// Transmit the framebuffer -static void WS2812_sendbuf() -{ - // transmission complete flag - ws2812b.transferComplete = 0; - - uint32_t i; - - for( i = 0; i < WS2812_BUFFER_COUNT; i++ ) - { - ws2812b.item[i].frameBufferCounter = 0; - - loadNextFramebufferData(&ws2812b.item[i], 0); // ROW 0 - loadNextFramebufferData(&ws2812b.item[i], 1); // ROW 0 - } - - // clear all DMA flags - __HAL_DMA_CLEAR_FLAG(&dmaUpdate, DMA_FLAG_TC2 | DMA_FLAG_HT2 | DMA_FLAG_TE2); - __HAL_DMA_CLEAR_FLAG(&dmaCC1, DMA_FLAG_TC5 | DMA_FLAG_HT5 | DMA_FLAG_TE5); - __HAL_DMA_CLEAR_FLAG(&dmaCC2, DMA_FLAG_TC7 | DMA_FLAG_HT7 | DMA_FLAG_TE7); - - // configure the number of bytes to be transferred by the DMA controller - dmaUpdate.Instance->CNDTR = BUFFER_SIZE; - dmaCC1.Instance->CNDTR = BUFFER_SIZE; - dmaCC2.Instance->CNDTR = BUFFER_SIZE; - - // clear all TIM2 flags - __HAL_TIM_CLEAR_FLAG(&Tim2Handle, TIM_FLAG_UPDATE | TIM_FLAG_CC1 | TIM_FLAG_CC2 | TIM_FLAG_CC3 | TIM_FLAG_CC4); - - // enable DMA channels - __HAL_DMA_ENABLE(&dmaUpdate); - __HAL_DMA_ENABLE(&dmaCC1); - __HAL_DMA_ENABLE(&dmaCC2); - - // IMPORTANT: enable the TIM2 DMA requests AFTER enabling the DMA channels! - __HAL_TIM_ENABLE_DMA(&Tim2Handle, TIM_DMA_UPDATE); - __HAL_TIM_ENABLE_DMA(&Tim2Handle, TIM_DMA_CC1); - __HAL_TIM_ENABLE_DMA(&Tim2Handle, TIM_DMA_CC2); - - TIM2->CNT = tim_period-1; - - // start TIM2 - __HAL_TIM_ENABLE(&Tim2Handle); -} - - - - - -void DMA_TransferHalfHandler(DMA_HandleTypeDef *DmaHandle) -{ - #if defined(LED4_PORT) - LED4_PORT->BSRR = LED4_PIN; - #endif - - // Is this the last LED? - if(ws2812b.repeatCounter != (WS2812B_NUMBER_OF_LEDS / 2 - 1)) - { - uint32_t i; - - for( i = 0; i < WS2812_BUFFER_COUNT; i++ ) - { - loadNextFramebufferData(&ws2812b.item[i], 0); - } - - } else { - // If this is the last pixel, set the next pixel value to zeros, because - // the DMA would not stop exactly at the last bit. - ws2812b_set_pixel(0, 0, 0, 0, 0); - } - - #if defined(LED4_PORT) - LED4_PORT->BRR = LED4_PIN; - #endif -} - -void DMA_TransferCompleteHandler(DMA_HandleTypeDef *DmaHandle) -{ - #if defined(LED5_PORT) - LED5_PORT->BSRR = LED5_PIN; - #endif - - ws2812b.repeatCounter++; - - if(ws2812b.repeatCounter == WS2812B_NUMBER_OF_LEDS / 2) - { - // Transfer of all LEDs is done, disable DMA but enable tiemr update IRQ to stop the 50us pulse - ws2812b.repeatCounter = 0; - - // Enable TIM2 Update interrupt for 50us Treset signal - __HAL_TIM_ENABLE_IT(&Tim2Handle, TIM_IT_UPDATE); - // Disable DMA - __HAL_DMA_DISABLE(&dmaUpdate); - __HAL_DMA_DISABLE(&dmaCC1); - __HAL_DMA_DISABLE(&dmaCC2); - - // Disable the DMA requests - __HAL_TIM_DISABLE_DMA(&Tim2Handle, TIM_DMA_UPDATE); - __HAL_TIM_DISABLE_DMA(&Tim2Handle, TIM_DMA_CC1); - __HAL_TIM_DISABLE_DMA(&Tim2Handle, TIM_DMA_CC2); - - // Manually set outputs to low to generate 50us reset impulse - WS2812B_PORT->BSRR = WS2812_IO_Low[0]; - } else { - - // Load bitbuffer with next RGB LED values - uint32_t i; - for( i = 0; i < WS2812_BUFFER_COUNT; i++ ) - { - loadNextFramebufferData(&ws2812b.item[i], 1); - } - - } - - #if defined(LED5_PORT) - LED5_PORT->BRR = LED5_PIN; - #endif -} - - -void TIM2_IRQHandler(void) -{ - HAL_TIM_IRQHandler(&Tim2Handle); -} - -// TIM2 Interrupt Handler gets executed on every TIM2 Update if enabled -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ - // I have to wait 50us to generate Treset signal - if (ws2812b.timerPeriodCounter < (uint8_t)WS2812_RESET_PERIOD) - { - // count the number of timer periods - ws2812b.timerPeriodCounter++; - } - else - { - ws2812b.timerPeriodCounter = 0; - __HAL_TIM_DISABLE(&Tim2Handle); - TIM2->CR1 = 0; // disable timer - - // disable the TIM2 Update - __HAL_TIM_DISABLE_IT(&Tim2Handle, TIM_IT_UPDATE); - // set TransferComplete flag - ws2812b.transferComplete = 1; - } - -} - - - -static void ws2812b_set_pixel(uint8_t row, uint16_t column, uint8_t red, uint8_t green, uint8_t blue) -{ - - // Apply gamma - red = gammaTable[red]; - green = gammaTable[green]; - blue = gammaTable[blue]; - - - uint32_t calcCol = (column*24); - uint32_t invRed = ~red; - uint32_t invGreen = ~green; - uint32_t invBlue = ~blue; - - -#if defined(SETPIX_1) - uint8_t i; - uint32_t calcClearRow = ~(0x01<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<>7)<> 7); - bitBand+=16; - - *bitBand = (invGreen >> 6); - bitBand+=16; - - *bitBand = (invGreen >> 5); - bitBand+=16; - - *bitBand = (invGreen >> 4); - bitBand+=16; - - *bitBand = (invGreen >> 3); - bitBand+=16; - - *bitBand = (invGreen >> 2); - bitBand+=16; - - *bitBand = (invGreen >> 1); - bitBand+=16; - - *bitBand = (invGreen >> 0); - bitBand+=16; - - // RED - *bitBand = (invRed >> 7); - bitBand+=16; - - *bitBand = (invRed >> 6); - bitBand+=16; - - *bitBand = (invRed >> 5); - bitBand+=16; - - *bitBand = (invRed >> 4); - bitBand+=16; - - *bitBand = (invRed >> 3); - bitBand+=16; - - *bitBand = (invRed >> 2); - bitBand+=16; - - *bitBand = (invRed >> 1); - bitBand+=16; - - *bitBand = (invRed >> 0); - bitBand+=16; - - // BLUE - *bitBand = (invBlue >> 7); - bitBand+=16; - - *bitBand = (invBlue >> 6); - bitBand+=16; - - *bitBand = (invBlue >> 5); - bitBand+=16; - - *bitBand = (invBlue >> 4); - bitBand+=16; - - *bitBand = (invBlue >> 3); - bitBand+=16; - - *bitBand = (invBlue >> 2); - bitBand+=16; - - *bitBand = (invBlue >> 1); - bitBand+=16; - - *bitBand = (invBlue >> 0); - bitBand+=16; +/* --- CONFIGURATION CHECK -------------------------------------------------- */ +#if !defined(WS2812_LED_N) + #error WS2812 LED chain length not specified +#elif WS2812_LED_N <= 0 + #error WS2812 LED chain length set to invalid value #endif + +#if !defined(WS2812_TIM_N) + #error WS2812 timer not specified +#elif WS2812_TIM_N == 1 + #define WS2812_DMA_STREAM STM32_DMA1_STREAM5 +#elif WS2812_TIM_N == 2 + #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 +#elif WS2812_TIM_N == 3 + #define WS2812_DMA_STREAM STM32_DMA1_STREAM3 +#elif WS2812_TIM_N == 4 + #define WS2812_DMA_STREAM STM32_DMA1_STREAM7 +#else + #error WS2812 timer set to invalid value +#endif + +#if !defined(WS2812_TIM_CH) + #error WS2812 timer channel not specified +#elif WS2812_TIM_CH >= 4 + #error WS2812 timer channel set to invalid value +#endif + +/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ + +#define WS2812_PWM_FREQUENCY (72000000) /**< Clock frequency of PWM */ +#define WS2812_PWM_PERIOD (90) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ + +/** + * @brief Number of bit-periods to hold the data line low at the end of a frame + * + * The reset period for each frame must be at least 50 uS; so we add in 50 bit-times + * of zeroes at the end. (50 bits)*(1.25 uS/bit) = 62.5 uS, which gives us some + * slack in the timing requirements + */ +#define WS2812_RESET_BIT_N (50) +#define WS2812_COLOR_BIT_N (WS2812_LED_N*24) /**< Number of data bits */ +#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N) /**< Total number of bits in a frame */ + +/** + * @brief High period for a zero, in ticks + * + * Per the datasheet: + * - T0H: 0.200 uS to 0.500 uS, inclusive + * - T0L: 0.650 uS to 0.950 uS, inclusive + * + * With a duty cycle of 22 ticks, we have a high period of 22/(72 MHz) = 3.06 uS, and + * a low period of (90 - 22)/(72 MHz) = 9.44 uS. These values are within the allowable + * bounds, and intentionally skewed as far to the low duty-cycle side as possible + */ +#define WS2812_DUTYCYCLE_0 (22) + +/** + * @brief High period for a one, in ticks + * + * Per the datasheet: + * - T0H: 0.550 uS to 0.850 uS, inclusive + * - T0L: 0.450 uS to 0.750 uS, inclusive + * + * With a duty cycle of 56 ticks, we have a high period of 56/(72 MHz) = 7.68 uS, and + * a low period of (90 - 56)/(72 MHz) = 4.72 uS. These values are within the allowable + * bounds, and intentionally skewed as far to the high duty-cycle side as possible + */ +#define WS2812_DUTYCYCLE_1 (56) + +/* --- PRIVATE MACROS ------------------------------------------------------- */ + +/** + * @brief Generates a reference to a numbered PWM driver + * + * @param[in] n: The driver (timer) number + * + * @return A reference to the driver + */ +#define PWMD(n) CONCAT_EXPANDED_SYMBOLS(PWMD, n) + +#define WS2812_PWMD PWMD(WS2812_TIM_N) /**< The PWM driver to use for the LED chain */ + +/** + * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given bit + * + * @param[in] led: The led index [0, @ref WS2812_LED_N) + * @param[in] byte: The byte number [0, 2] + * @param[in] bit: The bit number [0, 7] + * + * @return The bit index + */ +#define WS2812_BIT(led, byte, bit) (24*(led) + 8*(byte) + (7 - (bit))) + +/** + * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit + * + * @note The red byte is the middle byte in the color packet + * + * @param[in] led: The led index [0, @ref WS2812_LED_N) + * @param[in] bit: The bit number [0, 7] + * + * @return The bit index + */ +#define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 1, (bit)) + +/** + * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit + * + * @note The red byte is the first byte in the color packet + * + * @param[in] led: The led index [0, @ref WS2812_LED_N) + * @param[in] bit: The bit number [0, 7] + * + * @return The bit index + */ +#define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 0, (bit)) + +/** + * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit + * + * @note The red byte is the last byte in the color packet + * + * @param[in] led: The led index [0, @ref WS2812_LED_N) + * @param[in] bit: The bit index [0, 7] + * + * @return The bit index + */ +#define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit)) + +/* --- PRIVATE VARIABLES ---------------------------------------------------- */ + +static uint8_t ws2812_frame_buffer[WS2812_BIT_N]; /**< Buffer for a frame */ + +/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */ + +void ws2812_init(void) +{ + // Initialize led frame buffer + uint32_t i; + for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle + for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero + + // Configure PA0 as AF output + palSetPadMode(GPIOA, 1, PAL_MODE_ALTERNATE(1)); + + // PWM Configuration + #pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config + static const PWMConfig ws2812_pwm_config = { + .frequency = WS2812_PWM_FREQUENCY, + .period = WS2812_PWM_PERIOD, + .callback = NULL, + .channels = { + [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled + [WS2812_TIM_CH] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // Turn on the channel we care about + }, + .cr2 = 0, + .dier = TIM_DIER_UDE, // DMA on update event for next period + }; + #pragma GCC diagnostic pop // Restore command-line warning options + + // Configure DMA + dmaStreamAllocate(WS2812_DMA_STREAM, 10, NULL, NULL); + dmaStreamSetPeripheral(WS2812_DMA_STREAM, &(WS2812_PWMD.tim->CCR[WS2812_TIM_CH])); + dmaStreamSetMemory0(WS2812_DMA_STREAM, ws2812_frame_buffer); + dmaStreamSetTransactionSize(WS2812_DMA_STREAM, WS2812_BIT_N); + dmaStreamSetMode(WS2812_DMA_STREAM, + STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_BYTE | + STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); + + // Start DMA + dmaStreamEnable(WS2812_DMA_STREAM); + + // Configure PWM + // NOTE: It's required that preload be enabled on the timer channel CCR register. This is currently enabled in the + // ChibiOS driver code, so we don't have to do anything special to the timer. If we did, we'd have to start the timer, + // disable counting, enable the channel, and then make whatever configuration changes we need. + pwmStart(&WS2812_PWMD, &ws2812_pwm_config); + pwmEnableChannel(&WS2812_PWMD, WS2812_TIM_CH, 0); // Initial period is 0; output will be low until first duty cycle is DMA'd in +} + +ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b) +{ + // Check for valid LED + if (led_number >= WS2812_LED_N) return WS2812_LED_INVALID; + + // Write color to frame buffer + uint32_t bit; + for (bit = 0; bit < 8; bit++) { + ws2812_frame_buffer[WS2812_RED_BIT(led_number, bit)] = ((r >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0; + ws2812_frame_buffer[WS2812_GREEN_BIT(led_number, bit)] = ((g >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0; + ws2812_frame_buffer[WS2812_BLUE_BIT(led_number, bit)] = ((b >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0; + } + + // Success + return WS2812_SUCCESS; +} + +/** @} addtogroup WS2812 */ + +void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) { + ws2812_init(); + uint8_t i = 0; + while (i < number_of_leds) { + ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b); + i++; + } } -void ws2812b_init() -{ - ws2812b_gpio_init(); - DMA_init(); - TIM2_init(); +void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds) { - // Need to start the first transfer - ws2812b.transferComplete = 1; } - - -void ws2812b_handle() -{ - if(ws2812b.startTransfer) { - ws2812b.startTransfer = 0; - WS2812_sendbuf(); - } - -} \ No newline at end of file diff --git a/drivers/arm/ws2812.h b/drivers/arm/ws2812.h index 53a1787374..47e166e779 100644 --- a/drivers/arm/ws2812.h +++ b/drivers/arm/ws2812.h @@ -1,94 +1,102 @@ -/* +/** + * @file ws2812.h + * @author Austin Glaser + * @brief Interface to WS2812 LED driver + * + * Copyright (C) 2016 Austin Glaser + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + * + * @todo Put in names and descriptions of variables which need to be defined to use this file + */ - WS2812B CPU and memory efficient library +#ifndef WS2812_H_ +#define WS2812_H_ - Date: 28.9.2016 +/** + * @defgroup WS2812 WS2812 Driver + * @{ + * + * @brief DMA-based WS2812 LED driver + * + * A driver for WS2812 LEDs + */ - Author: Martin Hubacek - http://www.martinhubacek.cz - @hubmartin +/* --- PUBLIC DEPENDENCIES -------------------------------------------------- */ - Licence: MIT License +// Standard +#include +#include "rgblight_types.h" -*/ +/* --- PUBLIC CONSTANTS ----------------------------------------------------- */ -#ifndef WS2812B_H_ -#define WS2812B_H_ -#include "ws2812.h" +/** + * @brief Return codes from ws2812 interface functions + */ +typedef enum { + WS2812_SUCCESS = 0x00, /**< Operation completeed successfully */ + WS2812_LED_INVALID, /**< Attempted to index an invalid LED (@ref WS2812_N_LEDS) */ + MAX_WS2812_ERR, /**< Total number of possible error codes */ + WS2812_ERR_INVALID /**< Invalid error value */ +} ws2812_err_t; -// GPIO enable command -#define WS2812B_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE() -// LED output port -#define WS2812B_PORT GPIOC -// LED output pins -#define WS2812B_PINS (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3) -// How many LEDs are in the series -#define WS2812B_NUMBER_OF_LEDS 60 +/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */ -// Number of output LED strips. Each has its own buffer. -#define WS2812_BUFFER_COUNT 2 +/** + * @brief Initialize the driver + * + * After this function is called, all necessary background tasks will be started. + * The frame is initially dark. + */ +void ws2812_init(void); -// Choose one of the bit-juggling setpixel implementation -// ******************************************************* -//#define SETPIX_1 // For loop, works everywhere, slow -//#define SETPIX_2 // Bit band in a loop -//#define SETPIX_3 // Like SETPIX_1 but with unrolled loop -#define SETPIX_4 // Fastest copying using bit-banding +/** + * @brief Write the value of a single LED in the chain + * + * The color value is written to a frame buffer, and will not + * be updated until the next frame is written. Frames are written + * at the maximum possible speed -- the longest latency between a + * call to this function and the value being displayed is + * 1.25uS*(24*@ref WS2812_LED_N + 50) + * + * @param[in] led_number: The index of the LED to be written. Must be strictly less than + * @ref WS2812_N_LEDS + * @param[in] r: The red level of the LED + * @param[in] g: The green level of the LED + * @param[in] b: The blue level of the LED + * + * @retval WS2812_SUCCESS: The write was successful + * @retval WS2812_LED_INVALID: The write was to an invalid LED index + */ +ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b); +/** @} defgroup WS2812 */ -// DEBUG OUTPUT -// ******************** -#define LED4_PORT GPIOC -#define LED4_PIN GPIO_PIN_10 +void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); +void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); -#define LED5_PORT GPIOC -#define LED5_PIN GPIO_PIN_10 +/** + * @brief Concatenates two symbols s1 and s2 exactly, without expanding either + * + * @param[in] s1: The first symbol to concatenate + * @param[in] s2: The second symbol to concatenate + * + * @return A single symbol containing s1 and s2 concatenated without expansion + */ +#define CONCAT_SYMBOLS(s1, s2) s1##s2 +/** + * @brief Concatenate the symbols s1 and s2, expanding both of them + * + * This is important because simply applying s1##s2 doesn't expand them if they're + * preprocessor tokens themselves + * + * @param[in] s1: The first symbol to concatenate + * @param[in] s2: The second symbol to concatenate + * + * @return A single symbol containing s1 expanded followed by s2 expanded + */ +#define CONCAT_EXPANDED_SYMBOLS(s1, s2) CONCAT_SYMBOLS(s1, s2) -// Public functions -// **************** -void ws2812b_init(); -void ws2812b_handle(); - -// Library structures -// ****************** -// This value sets number of periods to generate 50uS Treset signal -#define WS2812_RESET_PERIOD 12 - -typedef struct WS2812_BufferItem { - uint8_t* frameBufferPointer; - uint32_t frameBufferSize; - uint32_t frameBufferCounter; - uint8_t channel; // digital output pin/channel -} WS2812_BufferItem; - - - -typedef struct WS2812_Struct -{ - WS2812_BufferItem item[WS2812_BUFFER_COUNT]; - uint8_t transferComplete; - uint8_t startTransfer; - uint32_t timerPeriodCounter; - uint32_t repeatCounter; -} WS2812_Struct; - -WS2812_Struct ws2812b; - -// Bit band stuff -#define RAM_BASE 0x20000000 -#define RAM_BB_BASE 0x22000000 -#define Var_ResetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 0) -#define Var_SetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2)) = 1) -#define Var_GetBit_BB(VarAddr, BitNumber) (*(volatile uint32_t *) (RAM_BB_BASE | ((VarAddr - RAM_BASE) << 5) | ((BitNumber) << 2))) -#define BITBAND_SRAM(address, bit) ( (__IO uint32_t *) (RAM_BB_BASE + (((uint32_t)address) - RAM_BASE) * 32 + (bit) * 4)) - -#define varSetBit(var,bit) (Var_SetBit_BB((uint32_t)&var,bit)) -#define varResetBit(var,bit) (Var_ResetBit_BB((uint32_t)&var,bit)) -#define varGetBit(var,bit) (Var_GetBit_BB((uint32_t)&var,bit)) - -static void ws2812b_set_pixel(uint8_t row, uint16_t column, uint8_t red, uint8_t green, uint8_t blue); -void DMA_TransferCompleteHandler(DMA_HandleTypeDef *DmaHandle); -void DMA_TransferHalfHandler(DMA_HandleTypeDef *DmaHandle); - -#endif /* WS2812B_H_ */ \ No newline at end of file +#endif /* WS2812_H_ */ diff --git a/keyboards/planck/config.h b/keyboards/planck/config.h index 452a99d746..097bacd715 100644 --- a/keyboards/planck/config.h +++ b/keyboards/planck/config.h @@ -18,7 +18,9 @@ along with this program. If not, see . #ifndef CONFIG_H #define CONFIG_H +#ifdef __AVR__ #include "config_common.h" +#endif /* USB Device descriptor parameter */ #define VENDOR_ID 0xFEED diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h index 831dabe62c..4fe91d963a 100644 --- a/keyboards/planck/rev6/config.h +++ b/keyboards/planck/rev6/config.h @@ -125,4 +125,9 @@ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 1 +#define WS2812_LED_N 1 +#define RGBLED_NUM WS2812_LED_N +#define WS2812_TIM_N 1 +#define WS2812_TIM_CH 1 + #endif diff --git a/keyboards/planck/rev6/halconf.h b/keyboards/planck/rev6/halconf.h index 8fe8e0c6f5..5e5d70219e 100644 --- a/keyboards/planck/rev6/halconf.h +++ b/keyboards/planck/rev6/halconf.h @@ -111,7 +111,7 @@ * @brief Enables the PWM subsystem. */ #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) -#define HAL_USE_PWM FALSE +#define HAL_USE_PWM TRUE #endif /** diff --git a/keyboards/planck/rev6/mcuconf.h b/keyboards/planck/rev6/mcuconf.h index 00179f69f1..b101957034 100644 --- a/keyboards/planck/rev6/mcuconf.h +++ b/keyboards/planck/rev6/mcuconf.h @@ -182,7 +182,7 @@ * PWM driver system settings. */ #define STM32_PWM_USE_ADVANCED FALSE -#define STM32_PWM_USE_TIM1 FALSE +#define STM32_PWM_USE_TIM1 TRUE #define STM32_PWM_USE_TIM2 FALSE #define STM32_PWM_USE_TIM3 FALSE #define STM32_PWM_USE_TIM4 FALSE diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 650e1a194d..45bd12d606 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -14,8 +14,12 @@ * along with this program. If not, see . */ #include "rev6.h" +#include "rgblight.h" void matrix_init_kb(void) { + rgblight_enable(); + rgblight_mode(1); + rgblight_setrgb(0xFF, 0xFF, 0xFF); matrix_init_user(); } diff --git a/keyboards/planck/rev6/rules.mk b/keyboards/planck/rev6/rules.mk index c49b528e3c..5d339fc88e 100644 --- a/keyboards/planck/rev6/rules.mk +++ b/keyboards/planck/rev6/rules.mk @@ -52,4 +52,5 @@ COMMAND_ENABLE = yes # Commands for debug and configuration NKRO_ENABLE = yes # USB Nkey Rollover CUSTOM_MATRIX = yes # Custom matrix file AUDIO_ENABLE = yes +RGBLIGHT_ENABLE = yes # SERIAL_LINK_ENABLE = yes diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 75512e97a7..5cfbf307c6 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -14,9 +14,11 @@ * along with this program. If not, see . */ #include -#include -#include -#include +#ifdef __AVR__ + #include + #include +#endif +#include "wait.h" #include "progmem.h" #include "timer.h" #include "rgblight.h" @@ -113,10 +115,16 @@ void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { uint32_t eeconfig_read_rgblight(void) { - return eeprom_read_dword(EECONFIG_RGBLIGHT); + #ifdef __AVR__ + return eeprom_read_dword(EECONFIG_RGBLIGHT); + #else + return 0; + #endif } void eeconfig_update_rgblight(uint32_t val) { - eeprom_update_dword(EECONFIG_RGBLIGHT, val); + #ifdef __AVR__ + eeprom_update_dword(EECONFIG_RGBLIGHT, val); + #endif } void eeconfig_update_rgblight_default(void) { dprintf("eeconfig_update_rgblight_default\n"); @@ -281,7 +289,7 @@ void rgblight_disable(void) { #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_disable(); #endif - _delay_ms(50); + wait_ms(50); rgblight_set(); } diff --git a/quantum/rgblight_types.h b/quantum/rgblight_types.h index b1aa7026c4..49ef5c8ea7 100644 --- a/quantum/rgblight_types.h +++ b/quantum/rgblight_types.h @@ -23,7 +23,9 @@ #ifndef RGBLIGHT_TYPES #define RGBLIGHT_TYPES -#include +#ifdef __AVR__ + #include +#endif #ifdef RGBW #define LED_TYPE struct cRGBW diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk index e53204905f..9febf6f6db 100644 --- a/tmk_core/chibios.mk +++ b/tmk_core/chibios.mk @@ -145,6 +145,8 @@ HEX = $(OBJCOPY) -O $(FORMAT) EEP = BIN = $(OBJCOPY) -O binary +COMMON_VPATH += $(DRIVER_PATH)/arm + THUMBFLAGS = -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb -DTHUMB COMPILEFLAGS += -fomit-frame-pointer From 1c0d85c1431e8cbd5129988f68ee7e56b999bbc8 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 22 May 2018 21:40:38 -0400 Subject: [PATCH 31/42] update build includes for chibios --- common.mk | 12 ++++++------ tmk_core/chibios.mk | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common.mk b/common.mk index 5b49680ea1..aea29a7a20 100644 --- a/common.mk +++ b/common.mk @@ -3,16 +3,16 @@ include message.mk # Directory common source files exist TOP_DIR = . TMK_DIR = tmk_core -TMK_PATH = $(TOP_DIR)/$(TMK_DIR) -LIB_PATH = $(TOP_DIR)/lib +TMK_PATH = $(TMK_DIR) +LIB_PATH = lib QUANTUM_DIR = quantum -QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR) +QUANTUM_PATH = $(QUANTUM_DIR) DRIVER_DIR = drivers -DRIVER_PATH = $(TOP_DIR)/$(DRIVER_DIR) +DRIVER_PATH = $(DRIVER_DIR) -BUILD_DIR := $(TOP_DIR)/.build +BUILD_DIR := .build COMMON_VPATH := $(TOP_DIR) COMMON_VPATH += $(TMK_PATH) @@ -21,4 +21,4 @@ COMMON_VPATH += $(QUANTUM_PATH)/keymap_extras COMMON_VPATH += $(QUANTUM_PATH)/audio COMMON_VPATH += $(QUANTUM_PATH)/process_keycode COMMON_VPATH += $(QUANTUM_PATH)/api -COMMON_VPATH += $(DRIVER_PATH) \ No newline at end of file +COMMON_VPATH += $(DRIVER_PATH) diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk index 9febf6f6db..25c49204bc 100644 --- a/tmk_core/chibios.mk +++ b/tmk_core/chibios.mk @@ -125,7 +125,7 @@ CHIBISRC := $(patsubst $(TOP_DIR)/%,%,$(CHIBISRC)) EXTRAINCDIRS += $(CHIBIOS)/os/license \ $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ - $(STREAMSINC) $(CHIBIOS)/os/various + $(STREAMSINC) $(CHIBIOS)/os/various $(COMMON_VPATH) # # Project, sources and paths From 3e282ab203bfa657bba85dd71bd2008062c3cff7 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Tue, 22 May 2018 21:41:10 -0400 Subject: [PATCH 32/42] update ws2812 driver/config --- drivers/arm/ws2812.c | 40 +++++++++++-------- keyboards/planck/config.h | 2 - .../rev6/boards/GENERIC_STM32_F303XC/board.h | 2 +- keyboards/planck/rev6/config.h | 5 +++ keyboards/planck/rev6/mcuconf.h | 1 - keyboards/planck/rev6/rev6.c | 1 + 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c index bab52e7531..f8730c6e1c 100644 --- a/drivers/arm/ws2812.c +++ b/drivers/arm/ws2812.c @@ -40,16 +40,17 @@ #if !defined(WS2812_TIM_N) #error WS2812 timer not specified -#elif WS2812_TIM_N == 1 - #define WS2812_DMA_STREAM STM32_DMA1_STREAM5 -#elif WS2812_TIM_N == 2 - #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 -#elif WS2812_TIM_N == 3 - #define WS2812_DMA_STREAM STM32_DMA1_STREAM3 -#elif WS2812_TIM_N == 4 - #define WS2812_DMA_STREAM STM32_DMA1_STREAM7 -#else - #error WS2812 timer set to invalid value +#endif +#if defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32F7XX) + #if WS2812_TIM_N <= 2 + #define WS2812_AF 1 + #elif WS2812_TIM_N <= 5 + #define WS2812_AF 2 + #elif WS2812_TIM_N <= 11 + #define WS2812_AF 3 + #endif +#elif !defined(WS2812_AF) + #error WS2812_AF timer alternate function not specified #endif #if !defined(WS2812_TIM_CH) @@ -60,8 +61,8 @@ /* --- PRIVATE CONSTANTS ---------------------------------------------------- */ -#define WS2812_PWM_FREQUENCY (72000000) /**< Clock frequency of PWM */ -#define WS2812_PWM_PERIOD (90) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ +#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */ +#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY/800000) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ /** * @brief Number of bit-periods to hold the data line low at the end of a frame @@ -85,7 +86,7 @@ * a low period of (90 - 22)/(72 MHz) = 9.44 uS. These values are within the allowable * bounds, and intentionally skewed as far to the low duty-cycle side as possible */ -#define WS2812_DUTYCYCLE_0 (22) +#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350)) /** * @brief High period for a one, in ticks @@ -98,7 +99,7 @@ * a low period of (90 - 56)/(72 MHz) = 4.72 uS. These values are within the allowable * bounds, and intentionally skewed as far to the high duty-cycle side as possible */ -#define WS2812_DUTYCYCLE_1 (56) +#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800)) /* --- PRIVATE MACROS ------------------------------------------------------- */ @@ -173,8 +174,12 @@ void ws2812_init(void) for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero - // Configure PA0 as AF output - palSetPadMode(GPIOA, 1, PAL_MODE_ALTERNATE(1)); + // Configure PA1 as AF output +#ifdef WS2812_EXTERNAL_PULLUP + palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF) | PAL_STM32_OTYPE_OPENDRAIN); +#else + palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF)); +#endif // PWM Configuration #pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config @@ -199,6 +204,8 @@ void ws2812_init(void) dmaStreamSetMode(WS2812_DMA_STREAM, STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_BYTE | STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); + //STM32_DMA_CR_CHSEL(WS2812_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_WORD | + //STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); // Start DMA dmaStreamEnable(WS2812_DMA_STREAM); @@ -231,7 +238,6 @@ ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t /** @} addtogroup WS2812 */ void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) { - ws2812_init(); uint8_t i = 0; while (i < number_of_leds) { ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b); diff --git a/keyboards/planck/config.h b/keyboards/planck/config.h index 097bacd715..452a99d746 100644 --- a/keyboards/planck/config.h +++ b/keyboards/planck/config.h @@ -18,9 +18,7 @@ along with this program. If not, see . #ifndef CONFIG_H #define CONFIG_H -#ifdef __AVR__ #include "config_common.h" -#endif /* USB Device descriptor parameter */ #define VENDOR_ID 0xFEED diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h index 7b8b826f68..77c1ee951d 100644 --- a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h @@ -25,7 +25,7 @@ * Board identifier. */ #define BOARD_GENERIC_STM32_F303XC -#define BOARD_NAME "Clueboard 60 PCB" +#define BOARD_NAME "Planck PCB" /* * Board oscillators-related settings. diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h index 4fe91d963a..aaa49710c1 100644 --- a/keyboards/planck/rev6/config.h +++ b/keyboards/planck/rev6/config.h @@ -129,5 +129,10 @@ #define RGBLED_NUM WS2812_LED_N #define WS2812_TIM_N 1 #define WS2812_TIM_CH 1 +#define PORT_WS2812 GPIOA +#define PIN_WS2812 1 +#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA stream for TIMx_UP (look up in reference manual under DMA Channel selection) +//#define WS2812_DMA_CHANNEL 7 // DMA channel for TIMx_UP +//#define WS2812_EXTERNAL_PULLUP #endif diff --git a/keyboards/planck/rev6/mcuconf.h b/keyboards/planck/rev6/mcuconf.h index b101957034..d30f08563e 100644 --- a/keyboards/planck/rev6/mcuconf.h +++ b/keyboards/planck/rev6/mcuconf.h @@ -184,7 +184,6 @@ #define STM32_PWM_USE_ADVANCED FALSE #define STM32_PWM_USE_TIM1 TRUE #define STM32_PWM_USE_TIM2 FALSE -#define STM32_PWM_USE_TIM3 FALSE #define STM32_PWM_USE_TIM4 FALSE #define STM32_PWM_USE_TIM8 FALSE #define STM32_PWM_TIM1_IRQ_PRIORITY 7 diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 45bd12d606..6789ff5c05 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -17,6 +17,7 @@ #include "rgblight.h" void matrix_init_kb(void) { + ws2812_init(); rgblight_enable(); rgblight_mode(1); rgblight_setrgb(0xFF, 0xFF, 0xFF); From d233737c95534dc42eee13d28bb98a0b8cca0e48 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 23 May 2018 00:50:58 -0400 Subject: [PATCH 33/42] last commit for glasser code --- drivers/arm/ws2812.c | 23 +++++++++++-------- .../rev6/boards/GENERIC_STM32_F303XC/board.h | 4 ++-- keyboards/planck/rev6/chconf.h | 2 +- keyboards/planck/rev6/config.h | 6 ++--- keyboards/planck/rev6/mcuconf.h | 6 ++--- keyboards/planck/rev6/rev6.c | 13 ++++++++--- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c index f8730c6e1c..91eb3a7c03 100644 --- a/drivers/arm/ws2812.c +++ b/drivers/arm/ws2812.c @@ -41,6 +41,7 @@ #if !defined(WS2812_TIM_N) #error WS2812 timer not specified #endif +// values for these might be found in table 14 in DM00058181 (STM32F303) #if defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32F7XX) #if WS2812_TIM_N <= 2 #define WS2812_AF 1 @@ -61,8 +62,10 @@ /* --- PRIVATE CONSTANTS ---------------------------------------------------- */ -#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */ -#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY/800000) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ +//#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */ +#define WS2812_PWM_FREQUENCY (72000000) /**< Clock frequency of PWM */ +//#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY/800000) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ +#define WS2812_PWM_PERIOD (90) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ /** * @brief Number of bit-periods to hold the data line low at the end of a frame @@ -86,7 +89,8 @@ * a low period of (90 - 22)/(72 MHz) = 9.44 uS. These values are within the allowable * bounds, and intentionally skewed as far to the low duty-cycle side as possible */ -#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350)) +//#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350)) +#define WS2812_DUTYCYCLE_0 (22) /** * @brief High period for a one, in ticks @@ -99,7 +103,8 @@ * a low period of (90 - 56)/(72 MHz) = 4.72 uS. These values are within the allowable * bounds, and intentionally skewed as far to the high duty-cycle side as possible */ -#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800)) +//#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800)) +#define WS2812_DUTYCYCLE_1 (56) /* --- PRIVATE MACROS ------------------------------------------------------- */ @@ -175,11 +180,11 @@ void ws2812_init(void) for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero // Configure PA1 as AF output -#ifdef WS2812_EXTERNAL_PULLUP - palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF) | PAL_STM32_OTYPE_OPENDRAIN); -#else - palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF)); -#endif +//#ifdef WS2812_EXTERNAL_PULLUP +// palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF) | PAL_STM32_OTYPE_OPENDRAIN); +//#else + palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(1)); +//#endif // PWM Configuration #pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h index 77c1ee951d..a748628abe 100644 --- a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h @@ -245,7 +245,7 @@ * PA15 - ROW4 */ #define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_PIN0) | \ - PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_ALTERNATE(GPIOA_PIN1) | \ PIN_MODE_INPUT(GPIOA_PIN2) | \ PIN_MODE_INPUT(GPIOA_PIN3) | \ PIN_MODE_INPUT(GPIOA_PIN4) | \ @@ -325,7 +325,7 @@ PIN_ODR_HIGH(GPIOA_SWCLK) | \ PIN_ODR_HIGH(GPIOA_PIN15)) #define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PIN0, 0) | \ - PIN_AFIO_AF(GPIOA_PIN1, 0) | \ + PIN_AFIO_AF(GPIOA_PIN1, 1) | \ PIN_AFIO_AF(GPIOA_PIN2, 0) | \ PIN_AFIO_AF(GPIOA_PIN3, 0) | \ PIN_AFIO_AF(GPIOA_PIN4, 0) | \ diff --git a/keyboards/planck/rev6/chconf.h b/keyboards/planck/rev6/chconf.h index 5a9b833107..b52ca7d2c8 100644 --- a/keyboards/planck/rev6/chconf.h +++ b/keyboards/planck/rev6/chconf.h @@ -41,7 +41,7 @@ * @brief System time counter resolution. * @note Allowed values are 16 or 32 bits. */ -#define CH_CFG_ST_RESOLUTION 32 +#define CH_CFG_ST_RESOLUTION 16 /** * @brief System tick frequency. diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h index aaa49710c1..0e462180bd 100644 --- a/keyboards/planck/rev6/config.h +++ b/keyboards/planck/rev6/config.h @@ -125,10 +125,10 @@ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 1 -#define WS2812_LED_N 1 +#define WS2812_LED_N 2 #define RGBLED_NUM WS2812_LED_N -#define WS2812_TIM_N 1 -#define WS2812_TIM_CH 1 +#define WS2812_TIM_N 2 +#define WS2812_TIM_CH 2 #define PORT_WS2812 GPIOA #define PIN_WS2812 1 #define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA stream for TIMx_UP (look up in reference manual under DMA Channel selection) diff --git a/keyboards/planck/rev6/mcuconf.h b/keyboards/planck/rev6/mcuconf.h index d30f08563e..e2be2a62ac 100644 --- a/keyboards/planck/rev6/mcuconf.h +++ b/keyboards/planck/rev6/mcuconf.h @@ -182,8 +182,8 @@ * PWM driver system settings. */ #define STM32_PWM_USE_ADVANCED FALSE -#define STM32_PWM_USE_TIM1 TRUE -#define STM32_PWM_USE_TIM2 FALSE +#define STM32_PWM_USE_TIM1 FALSE +#define STM32_PWM_USE_TIM2 TRUE #define STM32_PWM_USE_TIM4 FALSE #define STM32_PWM_USE_TIM8 FALSE #define STM32_PWM_TIM1_IRQ_PRIORITY 7 @@ -224,7 +224,7 @@ * ST driver system settings. */ #define STM32_ST_IRQ_PRIORITY 8 -#define STM32_ST_USE_TIMER 2 +#define STM32_ST_USE_TIMER 3 /* * UART driver system settings. diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 6789ff5c05..d53b2224a7 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -17,13 +17,20 @@ #include "rgblight.h" void matrix_init_kb(void) { + // rgblight_enable(); + // rgblight_mode(1); + // rgblight_setrgb(0xFF, 0xFF, 0xFF); ws2812_init(); - rgblight_enable(); - rgblight_mode(1); - rgblight_setrgb(0xFF, 0xFF, 0xFF); matrix_init_user(); } void matrix_scan_kb(void) { matrix_scan_user(); + + int s = 0; + for (int n = 0; n < WS2812_LED_N; n++) { + int s0 = s + 10*n; + ws2812_write_led(n, s0%255, (s0+85)%255, (s0+170)%255); + } + s += 10; } From af6107bee8b238f477e8c50b470c834a6b3a165a Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Wed, 23 May 2018 01:54:43 -0400 Subject: [PATCH 34/42] working example --- drivers/arm/ws2812.c | 379 +++++++----------- drivers/arm/ws2812.h | 105 +---- .../rev6/boards/GENERIC_STM32_F303XC/board.h | 4 +- keyboards/planck/rev6/mcuconf.h | 3 +- keyboards/planck/rev6/rev6.c | 15 +- 5 files changed, 169 insertions(+), 337 deletions(-) diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c index 91eb3a7c03..d55e2c2f47 100644 --- a/drivers/arm/ws2812.c +++ b/drivers/arm/ws2812.c @@ -1,253 +1,156 @@ -/** - * @file ws2812.c - * @author Austin Glaser - * @brief WS2812 LED driver +/* + * LEDDriver.c * - * Copyright (C) 2016 Austin Glaser - * - * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. - * - * @todo Put in names and descriptions of variables which need to be defined to use this file - * - * @addtogroup WS2812 - * @{ + * Created on: Aug 26, 2013 + * Author: Omri Iluz */ -/* --- PRIVATE DEPENDENCIES ------------------------------------------------- */ - -// This Driver #include "ws2812.h" +#include "stdlib.h" -// Standard -#include +static uint8_t *fb; +static int sLeds; +static stm32_gpio_t *sPort; +static uint32_t sMask; +uint8_t* dma_source; -// ChibiOS -#include "ch.h" -#include "hal.h" - -// Application -#include "board.h" -#include "util.h" - -/* --- CONFIGURATION CHECK -------------------------------------------------- */ - -#if !defined(WS2812_LED_N) - #error WS2812 LED chain length not specified -#elif WS2812_LED_N <= 0 - #error WS2812 LED chain length set to invalid value -#endif - -#if !defined(WS2812_TIM_N) - #error WS2812 timer not specified -#endif -// values for these might be found in table 14 in DM00058181 (STM32F303) -#if defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32F7XX) - #if WS2812_TIM_N <= 2 - #define WS2812_AF 1 - #elif WS2812_TIM_N <= 5 - #define WS2812_AF 2 - #elif WS2812_TIM_N <= 11 - #define WS2812_AF 3 - #endif -#elif !defined(WS2812_AF) - #error WS2812_AF timer alternate function not specified -#endif - -#if !defined(WS2812_TIM_CH) - #error WS2812 timer channel not specified -#elif WS2812_TIM_CH >= 4 - #error WS2812 timer channel set to invalid value -#endif - -/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ - -//#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */ -#define WS2812_PWM_FREQUENCY (72000000) /**< Clock frequency of PWM */ -//#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY/800000) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ -#define WS2812_PWM_PERIOD (90) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ - -/** - * @brief Number of bit-periods to hold the data line low at the end of a frame - * - * The reset period for each frame must be at least 50 uS; so we add in 50 bit-times - * of zeroes at the end. (50 bits)*(1.25 uS/bit) = 62.5 uS, which gives us some - * slack in the timing requirements - */ -#define WS2812_RESET_BIT_N (50) -#define WS2812_COLOR_BIT_N (WS2812_LED_N*24) /**< Number of data bits */ -#define WS2812_BIT_N (WS2812_COLOR_BIT_N + WS2812_RESET_BIT_N) /**< Total number of bits in a frame */ - -/** - * @brief High period for a zero, in ticks - * - * Per the datasheet: - * - T0H: 0.200 uS to 0.500 uS, inclusive - * - T0L: 0.650 uS to 0.950 uS, inclusive - * - * With a duty cycle of 22 ticks, we have a high period of 22/(72 MHz) = 3.06 uS, and - * a low period of (90 - 22)/(72 MHz) = 9.44 uS. These values are within the allowable - * bounds, and intentionally skewed as far to the low duty-cycle side as possible - */ -//#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350)) -#define WS2812_DUTYCYCLE_0 (22) - -/** - * @brief High period for a one, in ticks - * - * Per the datasheet: - * - T0H: 0.550 uS to 0.850 uS, inclusive - * - T0L: 0.450 uS to 0.750 uS, inclusive - * - * With a duty cycle of 56 ticks, we have a high period of 56/(72 MHz) = 7.68 uS, and - * a low period of (90 - 56)/(72 MHz) = 4.72 uS. These values are within the allowable - * bounds, and intentionally skewed as far to the high duty-cycle side as possible - */ -//#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800)) -#define WS2812_DUTYCYCLE_1 (56) - -/* --- PRIVATE MACROS ------------------------------------------------------- */ - -/** - * @brief Generates a reference to a numbered PWM driver - * - * @param[in] n: The driver (timer) number - * - * @return A reference to the driver - */ -#define PWMD(n) CONCAT_EXPANDED_SYMBOLS(PWMD, n) - -#define WS2812_PWMD PWMD(WS2812_TIM_N) /**< The PWM driver to use for the LED chain */ - -/** - * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given bit - * - * @param[in] led: The led index [0, @ref WS2812_LED_N) - * @param[in] byte: The byte number [0, 2] - * @param[in] bit: The bit number [0, 7] - * - * @return The bit index - */ -#define WS2812_BIT(led, byte, bit) (24*(led) + 8*(byte) + (7 - (bit))) - -/** - * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit - * - * @note The red byte is the middle byte in the color packet - * - * @param[in] led: The led index [0, @ref WS2812_LED_N) - * @param[in] bit: The bit number [0, 7] - * - * @return The bit index - */ -#define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 1, (bit)) - -/** - * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit - * - * @note The red byte is the first byte in the color packet - * - * @param[in] led: The led index [0, @ref WS2812_LED_N) - * @param[in] bit: The bit number [0, 7] - * - * @return The bit index - */ -#define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 0, (bit)) - -/** - * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit - * - * @note The red byte is the last byte in the color packet - * - * @param[in] led: The led index [0, @ref WS2812_LED_N) - * @param[in] bit: The bit index [0, 7] - * - * @return The bit index - */ -#define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit)) - -/* --- PRIVATE VARIABLES ---------------------------------------------------- */ - -static uint8_t ws2812_frame_buffer[WS2812_BIT_N]; /**< Buffer for a frame */ - -/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */ - -void ws2812_init(void) -{ - // Initialize led frame buffer - uint32_t i; - for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle - for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero - - // Configure PA1 as AF output -//#ifdef WS2812_EXTERNAL_PULLUP -// palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF) | PAL_STM32_OTYPE_OPENDRAIN); -//#else - palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(1)); -//#endif - - // PWM Configuration - #pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config - static const PWMConfig ws2812_pwm_config = { - .frequency = WS2812_PWM_FREQUENCY, - .period = WS2812_PWM_PERIOD, - .callback = NULL, - .channels = { - [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled - [WS2812_TIM_CH] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // Turn on the channel we care about - }, - .cr2 = 0, - .dier = TIM_DIER_UDE, // DMA on update event for next period - }; - #pragma GCC diagnostic pop // Restore command-line warning options - - // Configure DMA - dmaStreamAllocate(WS2812_DMA_STREAM, 10, NULL, NULL); - dmaStreamSetPeripheral(WS2812_DMA_STREAM, &(WS2812_PWMD.tim->CCR[WS2812_TIM_CH])); - dmaStreamSetMemory0(WS2812_DMA_STREAM, ws2812_frame_buffer); - dmaStreamSetTransactionSize(WS2812_DMA_STREAM, WS2812_BIT_N); - dmaStreamSetMode(WS2812_DMA_STREAM, - STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_BYTE | - STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); - //STM32_DMA_CR_CHSEL(WS2812_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_WORD | - //STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); - - // Start DMA - dmaStreamEnable(WS2812_DMA_STREAM); - - // Configure PWM - // NOTE: It's required that preload be enabled on the timer channel CCR register. This is currently enabled in the - // ChibiOS driver code, so we don't have to do anything special to the timer. If we did, we'd have to start the timer, - // disable counting, enable the channel, and then make whatever configuration changes we need. - pwmStart(&WS2812_PWMD, &ws2812_pwm_config); - pwmEnableChannel(&WS2812_PWMD, WS2812_TIM_CH, 0); // Initial period is 0; output will be low until first duty cycle is DMA'd in +void setColor(uint8_t color, uint8_t *buf,uint32_t mask){ + int i; + for (i=0;i<8;i++){ + buf[i]=((color<= WS2812_LED_N) return WS2812_LED_INVALID; - - // Write color to frame buffer - uint32_t bit; - for (bit = 0; bit < 8; bit++) { - ws2812_frame_buffer[WS2812_RED_BIT(led_number, bit)] = ((r >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0; - ws2812_frame_buffer[WS2812_GREEN_BIT(led_number, bit)] = ((g >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0; - ws2812_frame_buffer[WS2812_BLUE_BIT(led_number, bit)] = ((b >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0; - } - - // Success - return WS2812_SUCCESS; +void setColorRGB(Color c, uint8_t *buf, uint32_t mask){ + setColor(c.G,buf, mask); + setColor(c.R,buf+8, mask); + setColor(c.B,buf+16, mask); } -/** @} addtogroup WS2812 */ +/** + * @brief Initialize Led Driver + * @details Initialize the Led Driver based on parameters. + * Following initialization, the frame buffer would automatically be + * exported to the supplied port and pins in the right timing to drive + * a chain of WS2812B controllers + * @note The function assumes the controller is running at 72Mhz + * @note Timing is critical for WS2812. While all timing is done in hardware + * need to verify memory bandwidth is not exhausted to avoid DMA delays + * + * @param[in] leds length of the LED chain controlled by each pin + * @param[in] port which port would be used for output + * @param[in] mask Which pins would be used for output, each pin is a full chain + * @param[out] o_fb initialized frame buffer + * + */ +void ledDriverInit(int leds, stm32_gpio_t *port, uint32_t mask, uint8_t **o_fb) { + sLeds=leds; + sPort=port; + sMask=mask; + palSetGroupMode(port, sMask, 0, PAL_MODE_OUTPUT_PUSHPULL|PAL_STM32_OSPEED_HIGHEST|PAL_STM32_PUPDR_FLOATING); + + // configure pwm timers - + // timer 2 as master, active for data transmission and inactive to disable transmission during reset period (50uS) + // timer 3 as slave, during active time creates a 1.25 uS signal, with duty cycle controlled by frame buffer values + static PWMConfig pwmc2 = {72000000 / 90, /* 800Khz PWM clock frequency. 1/90 of PWMC3 */ + (72000000 / 90) * 0.05, /*Total period is 50ms (20FPS), including sLeds cycles + reset length for ws2812b and FB writes */ + NULL, + { {PWM_OUTPUT_ACTIVE_HIGH, NULL}, + {PWM_OUTPUT_DISABLED, NULL}, + {PWM_OUTPUT_DISABLED, NULL}, + {PWM_OUTPUT_DISABLED, NULL}}, + TIM_CR2_MMS_2, /* master mode selection */ + 0, }; + /* master mode selection */ + static PWMConfig pwmc3 = {72000000,/* 72Mhz PWM clock frequency. */ + 90, /* 90 cycles period (1.25 uS per period @72Mhz */ + NULL, + { {PWM_OUTPUT_ACTIVE_HIGH, NULL}, + {PWM_OUTPUT_ACTIVE_HIGH, NULL}, + {PWM_OUTPUT_ACTIVE_HIGH, NULL}, + {PWM_OUTPUT_ACTIVE_HIGH, NULL}}, + 0, + 0, + }; + dma_source = chHeapAlloc(NULL, 1); + fb = chHeapAlloc(NULL, ((sLeds) * 24)+10); + *o_fb=fb; + int j; + for (j = 0; j < (sLeds) * 24; j++) fb[j] = 0; + dma_source[0] = sMask; + // DMA stream 2, triggered by channel3 pwm signal. if FB indicates, reset output value early to indicate "0" bit to ws2812 + dmaStreamAllocate(STM32_DMA1_STREAM2, 10, NULL, NULL); + dmaStreamSetPeripheral(STM32_DMA1_STREAM2, &(sPort->BSRR.H.clear)); + dmaStreamSetMemory0(STM32_DMA1_STREAM2, fb); + dmaStreamSetTransactionSize(STM32_DMA1_STREAM2, (sLeds) * 24); + dmaStreamSetMode( + STM32_DMA1_STREAM2, + STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_MINC | STM32_DMA_CR_PSIZE_BYTE + | STM32_DMA_CR_MSIZE_BYTE | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(2)); + // DMA stream 3, triggered by pwm update event. output high at beginning of signal + dmaStreamAllocate(STM32_DMA1_STREAM3, 10, NULL, NULL); + dmaStreamSetPeripheral(STM32_DMA1_STREAM3, &(sPort->BSRR.H.set)); + dmaStreamSetMemory0(STM32_DMA1_STREAM3, dma_source); + dmaStreamSetTransactionSize(STM32_DMA1_STREAM3, 1); + dmaStreamSetMode( + STM32_DMA1_STREAM3, STM32_DMA_CR_TEIE | + STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE + | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); + // DMA stream 6, triggered by channel1 update event. reset output value late to indicate "1" bit to ws2812. + // always triggers but no affect if dma stream 2 already change output value to 0 + dmaStreamAllocate(STM32_DMA1_STREAM6, 10, NULL, NULL); + dmaStreamSetPeripheral(STM32_DMA1_STREAM6, &(sPort->BSRR.H.clear)); + dmaStreamSetMemory0(STM32_DMA1_STREAM6, dma_source); + dmaStreamSetTransactionSize(STM32_DMA1_STREAM6, 1); + dmaStreamSetMode( + STM32_DMA1_STREAM6, + STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE + | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); + pwmStart(&PWMD2, &pwmc2); + pwmStart(&PWMD3, &pwmc3); + // set pwm3 as slave, triggerd by pwm2 oc1 event. disables pwmd2 for synchronization. + PWMD3.tim->SMCR |= TIM_SMCR_SMS_0 | TIM_SMCR_SMS_2 | TIM_SMCR_TS_0; + PWMD2.tim->CR1 &= ~TIM_CR1_CEN; + // set pwm values. + // 28 (duty in ticks) / 90 (period in ticks) * 1.25uS (period in S) = 0.39 uS + pwmEnableChannel(&PWMD3, 2, 28); + // 58 (duty in ticks) / 90 (period in ticks) * 1.25uS (period in S) = 0.806 uS + pwmEnableChannel(&PWMD3, 0, 58); + // active during transfer of 90 cycles * sLeds * 24 bytes * 1/90 multiplier + pwmEnableChannel(&PWMD2, 0, 90 * sLeds * 24 / 90); + // stop and reset counters for synchronization + PWMD2.tim->CNT = 0; + // Slave (TIM3) needs to "update" immediately after master (TIM2) start in order to start in sync. + // this initial sync is crucial for the stability of the run + PWMD3.tim->CNT = 89; + PWMD3.tim->DIER |= TIM_DIER_CC3DE | TIM_DIER_CC1DE | TIM_DIER_UDE; + dmaStreamEnable(STM32_DMA1_STREAM3); + dmaStreamEnable(STM32_DMA1_STREAM6); + dmaStreamEnable(STM32_DMA1_STREAM2); + // all systems go! both timers and all channels are configured to resonate + // in complete sync without any need for CPU cycles (only DMA and timers) + // start pwm2 for system to start resonating + PWMD2.tim->CR1 |= TIM_CR1_CEN; +} + +void ledDriverWaitCycle(void){ + while (PWMD2.tim->CNT < 90 * sLeds * 24 / 90){chThdSleepMicroseconds(1);}; +} + +void testPatternFB(uint8_t *fb){ + int i; + Color tmpC = {rand()%256, rand()%256, rand()%256}; + for (i=0;i - * @brief Interface to WS2812 LED driver +/* + * LEDDriver.h * - * Copyright (C) 2016 Austin Glaser - * - * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. - * - * @todo Put in names and descriptions of variables which need to be defined to use this file + * Created on: Aug 26, 2013 + * Author: Omri Iluz */ #ifndef WS2812_H_ #define WS2812_H_ -/** - * @defgroup WS2812 WS2812 Driver - * @{ - * - * @brief DMA-based WS2812 LED driver - * - * A driver for WS2812 LEDs - */ - -/* --- PUBLIC DEPENDENCIES -------------------------------------------------- */ - -// Standard -#include +#include "hal.h" #include "rgblight_types.h" -/* --- PUBLIC CONSTANTS ----------------------------------------------------- */ +#define sign(x) (( x > 0 ) - ( x < 0 )) -/** - * @brief Return codes from ws2812 interface functions - */ -typedef enum { - WS2812_SUCCESS = 0x00, /**< Operation completeed successfully */ - WS2812_LED_INVALID, /**< Attempted to index an invalid LED (@ref WS2812_N_LEDS) */ - MAX_WS2812_ERR, /**< Total number of possible error codes */ - WS2812_ERR_INVALID /**< Invalid error value */ -} ws2812_err_t; +typedef struct Color Color; +struct Color { + uint8_t R; + uint8_t G; + uint8_t B; +}; -/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */ - -/** - * @brief Initialize the driver - * - * After this function is called, all necessary background tasks will be started. - * The frame is initially dark. - */ -void ws2812_init(void); - -/** - * @brief Write the value of a single LED in the chain - * - * The color value is written to a frame buffer, and will not - * be updated until the next frame is written. Frames are written - * at the maximum possible speed -- the longest latency between a - * call to this function and the value being displayed is - * 1.25uS*(24*@ref WS2812_LED_N + 50) - * - * @param[in] led_number: The index of the LED to be written. Must be strictly less than - * @ref WS2812_N_LEDS - * @param[in] r: The red level of the LED - * @param[in] g: The green level of the LED - * @param[in] b: The blue level of the LED - * - * @retval WS2812_SUCCESS: The write was successful - * @retval WS2812_LED_INVALID: The write was to an invalid LED index - */ -ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b); - -/** @} defgroup WS2812 */ +void ledDriverInit(int leds, stm32_gpio_t *port, uint32_t mask, uint8_t **o_fb); +void setColorRGB(Color c, uint8_t *buf, uint32_t mask); +void testPatternFB(uint8_t *fb); +void ledDriverWaitCycle(void); void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); -/** - * @brief Concatenates two symbols s1 and s2 exactly, without expanding either - * - * @param[in] s1: The first symbol to concatenate - * @param[in] s2: The second symbol to concatenate - * - * @return A single symbol containing s1 and s2 concatenated without expansion - */ -#define CONCAT_SYMBOLS(s1, s2) s1##s2 - -/** - * @brief Concatenate the symbols s1 and s2, expanding both of them - * - * This is important because simply applying s1##s2 doesn't expand them if they're - * preprocessor tokens themselves - * - * @param[in] s1: The first symbol to concatenate - * @param[in] s2: The second symbol to concatenate - * - * @return A single symbol containing s1 expanded followed by s2 expanded - */ -#define CONCAT_EXPANDED_SYMBOLS(s1, s2) CONCAT_SYMBOLS(s1, s2) - -#endif /* WS2812_H_ */ +#endif /* LEDDRIVER_H_ */ diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h index a748628abe..ec26557f3a 100644 --- a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h @@ -277,7 +277,7 @@ PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) | \ PIN_OTYPE_PUSHPULL(GPIOA_PIN15)) #define VAL_GPIOA_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOA_PIN0) | \ - PIN_OSPEED_VERYLOW(GPIOA_PIN1) | \ + PIN_OSPEED_HIGH(GPIOA_PIN1) | \ PIN_OSPEED_VERYLOW(GPIOA_PIN2) | \ PIN_OSPEED_VERYLOW(GPIOA_PIN3) | \ PIN_OSPEED_VERYLOW(GPIOA_PIN4) | \ @@ -293,7 +293,7 @@ PIN_OSPEED_HIGH(GPIOA_SWCLK) | \ PIN_OSPEED_VERYLOW(GPIOA_PIN15)) #define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_PIN0) | \ - PIN_PUPDR_PULLUP(GPIOA_PIN1) | \ + PIN_PUPDR_FLOATING(GPIOA_PIN1) | \ PIN_PUPDR_PULLUP(GPIOA_PIN2) | \ PIN_PUPDR_PULLUP(GPIOA_PIN3) | \ PIN_PUPDR_PULLUP(GPIOA_PIN4) | \ diff --git a/keyboards/planck/rev6/mcuconf.h b/keyboards/planck/rev6/mcuconf.h index e2be2a62ac..2d27bee4e6 100644 --- a/keyboards/planck/rev6/mcuconf.h +++ b/keyboards/planck/rev6/mcuconf.h @@ -184,6 +184,7 @@ #define STM32_PWM_USE_ADVANCED FALSE #define STM32_PWM_USE_TIM1 FALSE #define STM32_PWM_USE_TIM2 TRUE +#define STM32_PWM_USE_TIM3 TRUE #define STM32_PWM_USE_TIM4 FALSE #define STM32_PWM_USE_TIM8 FALSE #define STM32_PWM_TIM1_IRQ_PRIORITY 7 @@ -224,7 +225,7 @@ * ST driver system settings. */ #define STM32_ST_IRQ_PRIORITY 8 -#define STM32_ST_USE_TIMER 3 +#define STM32_ST_USE_TIMER 4 /* * UART driver system settings. diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index d53b2224a7..0011d3e789 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -16,21 +16,20 @@ #include "rev6.h" #include "rgblight.h" + uint8_t *o_fb; + void matrix_init_kb(void) { // rgblight_enable(); // rgblight_mode(1); // rgblight_setrgb(0xFF, 0xFF, 0xFF); - ws2812_init(); + + ledDriverInit(2, GPIOA, 0b00000010, &o_fb); + testPatternFB(o_fb); + matrix_init_user(); } void matrix_scan_kb(void) { matrix_scan_user(); - - int s = 0; - for (int n = 0; n < WS2812_LED_N; n++) { - int s0 = s + 10*n; - ws2812_write_led(n, s0%255, (s0+85)%255, (s0+170)%255); - } - s += 10; + testPatternFB(o_fb); } From 161c68b48ace5ca0bba5cc24f647a14e77800bd8 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 31 May 2018 00:27:55 -0400 Subject: [PATCH 35/42] update twi2c to do standard master stuff --- drivers/arm/is31fl3731.c | 242 +++++++++++++++++++++++++++++++ drivers/arm/is31fl3731.h | 214 +++++++++++++++++++++++++++ drivers/arm/twi2c.c | 33 +++-- drivers/arm/twi2c.h | 11 +- keyboards/_qmk_handwire/matrix.c | 2 +- lib/chibios | 2 +- 6 files changed, 489 insertions(+), 15 deletions(-) create mode 100644 drivers/arm/is31fl3731.c create mode 100644 drivers/arm/is31fl3731.h diff --git a/drivers/arm/is31fl3731.c b/drivers/arm/is31fl3731.c new file mode 100644 index 0000000000..f815ef94c5 --- /dev/null +++ b/drivers/arm/is31fl3731.c @@ -0,0 +1,242 @@ +/* Copyright 2017 Jason Williams + * Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "is31fl3731.h" +#include +#include +#include "twi2c.h" +#include "progmem.h" + +// This is a 7-bit address, that gets left-shifted and bit 0 +// set to 0 for write, 1 for read (as per I2C protocol) +// The address will vary depending on your wiring: +// 0b1110100 AD <-> GND +// 0b1110111 AD <-> VCC +// 0b1110101 AD <-> SCL +// 0b1110110 AD <-> SDA +#define ISSI_ADDR_DEFAULT 0x74 + +#define ISSI_REG_CONFIG 0x00 +#define ISSI_REG_CONFIG_PICTUREMODE 0x00 +#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08 +#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18 + +#define ISSI_CONF_PICTUREMODE 0x00 +#define ISSI_CONF_AUTOFRAMEMODE 0x04 +#define ISSI_CONF_AUDIOMODE 0x08 + +#define ISSI_REG_PICTUREFRAME 0x01 + +#define ISSI_REG_SHUTDOWN 0x0A +#define ISSI_REG_AUDIOSYNC 0x06 + +#define ISSI_COMMANDREGISTER 0xFD +#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' + +// Transfer buffer for TWITransmitData() +uint8_t g_twi_transfer_buffer[20]; + +// These buffers match the IS31FL3731 PWM registers 0x24-0xB3. +// Storing them like this is optimal for I2C transfers to the registers. +// We could optimize this and take out the unused registers from these +// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's +// probably not worth the extra complexity. +uint8_t g_pwm_buffer[DRIVER_COUNT][144]; +bool g_pwm_buffer_update_required = false; + +uint8_t g_led_control_registers[DRIVER_COUNT][18] = { { 0 }, { 0 } }; +bool g_led_control_registers_update_required = false; + +// This is the bit pattern in the LED control registers +// (for matrix A, add one to register for matrix B) +// +// reg - b7 b6 b5 b4 b3 b2 b1 b0 +// 0x00 - R08,R07,R06,R05,R04,R03,R02,R01 +// 0x02 - G08,G07,G06,G05,G04,G03,G02,R00 +// 0x04 - B08,B07,B06,B05,B04,B03,G01,G00 +// 0x06 - - , - , - , - , - ,B02,B01,B00 +// 0x08 - - , - , - , - , - , - , - , - +// 0x0A - B17,B16,B15, - , - , - , - , - +// 0x0C - G17,G16,B14,B13,B12,B11,B10,B09 +// 0x0E - R17,G15,G14,G13,G12,G11,G10,G09 +// 0x10 - R16,R15,R14,R13,R12,R11,R10,R09 + + +void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data ) +{ + g_twi_transfer_buffer[0] = reg; + g_twi_transfer_buffer[1] = data; + + //Transmit data until succesful + while(twi2c_transmit(addr << 1, g_twi_transfer_buffer,2) != 0); +} + +void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ) +{ + // assumes bank is already selected + + // transmit PWM registers in 9 transfers of 16 bytes + // g_twi_transfer_buffer[] is 20 bytes + + // iterate over the pwm_buffer contents at 16 byte intervals + for ( int i = 0; i < 144; i += 16 ) + { + // set the first register, e.g. 0x24, 0x34, 0x44, etc. + g_twi_transfer_buffer[0] = 0x24 + i; + // copy the data from i to i+15 + // device will auto-increment register for data after the first byte + // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer + for ( int j = 0; j < 16; j++ ) + { + g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; + } + + //Transmit buffer until succesful + while(twi2c_transmit(addr << 1, g_twi_transfer_buffer,17) != 0); + } +} + +void IS31FL3731_init( uint8_t addr ) +{ + // In order to avoid the LEDs being driven with garbage data + // in the LED driver's PWM registers, first enable software shutdown, + // then set up the mode and other settings, clear the PWM registers, + // then disable software shutdown. + + // select "function register" bank + IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG ); + + // enable software shutdown + IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x00 ); + // this delay was copied from other drivers, might not be needed + _delay_ms( 10 ); + + // picture mode + IS31FL3731_write_register( addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE ); + // display frame 0 + IS31FL3731_write_register( addr, ISSI_REG_PICTUREFRAME, 0x00 ); + // audio sync off + IS31FL3731_write_register( addr, ISSI_REG_AUDIOSYNC, 0x00 ); + + // select bank 0 + IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 ); + + // turn off all LEDs in the LED control register + for ( int i = 0x00; i <= 0x11; i++ ) + { + IS31FL3731_write_register( addr, i, 0x00 ); + } + + // turn off all LEDs in the blink control register (not really needed) + for ( int i = 0x12; i <= 0x23; i++ ) + { + IS31FL3731_write_register( addr, i, 0x00 ); + } + + // set PWM on all LEDs to 0 + for ( int i = 0x24; i <= 0xB3; i++ ) + { + IS31FL3731_write_register( addr, i, 0x00 ); + } + + // select "function register" bank + IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG ); + + // disable software shutdown + IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x01 ); + + // select bank 0 and leave it selected. + // most usage after initialization is just writing PWM buffers in bank 0 + // as there's not much point in double-buffering + IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 ); +} + +void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) +{ + if ( index >= 0 && index < DRIVER_LED_TOTAL ) { + is31_led led = g_is31_leds[index]; + + // Subtract 0x24 to get the second index of g_pwm_buffer + g_pwm_buffer[led.driver][led.r - 0x24] = red; + g_pwm_buffer[led.driver][led.g - 0x24] = green; + g_pwm_buffer[led.driver][led.b - 0x24] = blue; + g_pwm_buffer_update_required = true; + } +} + +void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) +{ + for ( int i = 0; i < DRIVER_LED_TOTAL; i++ ) + { + IS31FL3731_set_color( i, red, green, blue ); + } +} + +void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue ) +{ + is31_led led = g_is31_leds[index]; + + uint8_t control_register_r = (led.r - 0x24) / 8; + uint8_t control_register_g = (led.g - 0x24) / 8; + uint8_t control_register_b = (led.b - 0x24) / 8; + uint8_t bit_r = (led.r - 0x24) % 8; + uint8_t bit_g = (led.g - 0x24) % 8; + uint8_t bit_b = (led.b - 0x24) % 8; + + if ( red ) { + g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r); + } else { + g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r); + } + if ( green ) { + g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g); + } else { + g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g); + } + if ( blue ) { + g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b); + } else { + g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b); + } + + g_led_control_registers_update_required = true; + + +} + +void IS31FL3731_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ) +{ + if ( g_pwm_buffer_update_required ) + { + IS31FL3731_write_pwm_buffer( addr1, g_pwm_buffer[0] ); + IS31FL3731_write_pwm_buffer( addr2, g_pwm_buffer[1] ); + } + g_pwm_buffer_update_required = false; +} + +void IS31FL3731_update_led_control_registers( uint8_t addr1, uint8_t addr2 ) +{ + if ( g_led_control_registers_update_required ) + { + for ( int i=0; i<18; i++ ) + { + IS31FL3731_write_register(addr1, i, g_led_control_registers[0][i] ); + IS31FL3731_write_register(addr2, i, g_led_control_registers[1][i] ); + } + } +} + diff --git a/drivers/arm/is31fl3731.h b/drivers/arm/is31fl3731.h new file mode 100644 index 0000000000..f354a12db2 --- /dev/null +++ b/drivers/arm/is31fl3731.h @@ -0,0 +1,214 @@ +/* Copyright 2017 Jason Williams + * Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef IS31FL3731_DRIVER_H +#define IS31FL3731_DRIVER_H + +#include +#include + +typedef struct is31_led { + uint8_t driver:2; + uint8_t r; + uint8_t g; + uint8_t b; +} __attribute__((packed)) is31_led; + +extern const is31_led g_is31_leds[DRIVER_LED_TOTAL]; + +void IS31FL3731_init( uint8_t addr ); +void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data ); +void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ); + +void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ); +void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue ); + +void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue ); + +// This should not be called from an interrupt +// (eg. from a timer interrupt). +// Call this while idle (in between matrix scans). +// If the buffer is dirty, it will update the driver with the buffer. +void IS31FL3731_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ); +void IS31FL3731_update_led_control_registers( uint8_t addr1, uint8_t addr2 ); + +#define C1_1 0x24 +#define C1_2 0x25 +#define C1_3 0x26 +#define C1_4 0x27 +#define C1_5 0x28 +#define C1_6 0x29 +#define C1_7 0x2A +#define C1_8 0x2B + +#define C1_9 0x2C +#define C1_10 0x2D +#define C1_11 0x2E +#define C1_12 0x2F +#define C1_13 0x30 +#define C1_14 0x31 +#define C1_15 0x32 +#define C1_16 0x33 + +#define C2_1 0x34 +#define C2_2 0x35 +#define C2_3 0x36 +#define C2_4 0x37 +#define C2_5 0x38 +#define C2_6 0x39 +#define C2_7 0x3A +#define C2_8 0x3B + +#define C2_9 0x3C +#define C2_10 0x3D +#define C2_11 0x3E +#define C2_12 0x3F +#define C2_13 0x40 +#define C2_14 0x41 +#define C2_15 0x42 +#define C2_16 0x43 + +#define C3_1 0x44 +#define C3_2 0x45 +#define C3_3 0x46 +#define C3_4 0x47 +#define C3_5 0x48 +#define C3_6 0x49 +#define C3_7 0x4A +#define C3_8 0x4B + +#define C3_9 0x4C +#define C3_10 0x4D +#define C3_11 0x4E +#define C3_12 0x4F +#define C3_13 0x50 +#define C3_14 0x51 +#define C3_15 0x52 +#define C3_16 0x53 + +#define C4_1 0x54 +#define C4_2 0x55 +#define C4_3 0x56 +#define C4_4 0x57 +#define C4_5 0x58 +#define C4_6 0x59 +#define C4_7 0x5A +#define C4_8 0x5B + +#define C4_9 0x5C +#define C4_10 0x5D +#define C4_11 0x5E +#define C4_12 0x5F +#define C4_13 0x60 +#define C4_14 0x61 +#define C4_15 0x62 +#define C4_16 0x63 + +#define C5_1 0x64 +#define C5_2 0x65 +#define C5_3 0x66 +#define C5_4 0x67 +#define C5_5 0x68 +#define C5_6 0x69 +#define C5_7 0x6A +#define C5_8 0x6B + +#define C5_9 0x6C +#define C5_10 0x6D +#define C5_11 0x6E +#define C5_12 0x6F +#define C5_13 0x70 +#define C5_14 0x71 +#define C5_15 0x72 +#define C5_16 0x73 + +#define C6_1 0x74 +#define C6_2 0x75 +#define C6_3 0x76 +#define C6_4 0x77 +#define C6_5 0x78 +#define C6_6 0x79 +#define C6_7 0x7A +#define C6_8 0x7B + +#define C6_9 0x7C +#define C6_10 0x7D +#define C6_11 0x7E +#define C6_12 0x7F +#define C6_13 0x80 +#define C6_14 0x81 +#define C6_15 0x82 +#define C6_16 0x83 + +#define C7_1 0x84 +#define C7_2 0x85 +#define C7_3 0x86 +#define C7_4 0x87 +#define C7_5 0x88 +#define C7_6 0x89 +#define C7_7 0x8A +#define C7_8 0x8B + +#define C7_9 0x8C +#define C7_10 0x8D +#define C7_11 0x8E +#define C7_12 0x8F +#define C7_13 0x90 +#define C7_14 0x91 +#define C7_15 0x92 +#define C7_16 0x93 + +#define C8_1 0x94 +#define C8_2 0x95 +#define C8_3 0x96 +#define C8_4 0x97 +#define C8_5 0x98 +#define C8_6 0x99 +#define C8_7 0x9A +#define C8_8 0x9B + +#define C8_9 0x9C +#define C8_10 0x9D +#define C8_11 0x9E +#define C8_12 0x9F +#define C8_13 0xA0 +#define C8_14 0xA1 +#define C8_15 0xA2 +#define C8_16 0xA3 + +#define C9_1 0xA4 +#define C9_2 0xA5 +#define C9_3 0xA6 +#define C9_4 0xA7 +#define C9_5 0xA8 +#define C9_6 0xA9 +#define C9_7 0xAA +#define C9_8 0xAB + +#define C9_9 0xAC +#define C9_10 0xAD +#define C9_11 0xAE +#define C9_12 0xAF +#define C9_13 0xB0 +#define C9_14 0xB1 +#define C9_15 0xB2 +#define C9_16 0xB3 + + + +#endif // IS31FL3731_DRIVER_H diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 7200d2db95..08d23b6160 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -39,7 +39,9 @@ I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; -static const I2CConfig slaveI2CConfig = { +static uint8_t twi2c_address; + +static const I2CConfig I2CConfig = { STM32_TIMINGR_PRESC(15U) | STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) | STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U), @@ -166,15 +168,10 @@ void clearAfterSend(I2CDriver *i2cp) void twi2c_slave_init(void) { - palSetGroupMode(GPIOB,8,9, PAL_MODE_INPUT); // Try releasing special pins for a short time - chThdSleepMilliseconds(10); - - /* I2C1 SCL on PF1, SDA on PF0 */ - palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); - palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + twi2c_init(); - i2cStart(&I2C_DRIVER, &slaveI2CConfig); + i2cStart(&I2C_DRIVER, &I2CConfig); #if HAL_USE_I2C_SLAVE I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message #endif @@ -201,19 +198,31 @@ void twi2c_slave_task(void) { } } -void twi2c_master_init(void) { +uint8_t twi2c_start(uint8_t address) { + twi2c_address = address; + i2cStart(&I2C_DRIVER, &I2CConfig); +} +void twi2c_init(void) { palSetGroupMode(GPIOB,8,9, PAL_MODE_INPUT); // Try releasing special pins for a short time chThdSleepMilliseconds(10); palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); - i2cStart(&I2C_DRIVER, &slaveI2CConfig); - // try high drive (from kiibohd) // I2C_DRIVER.i2c->C2 |= I2Cx_C2_HDRS; // try glitch fixing (from kiibohd) // I2C_DRIVER.i2c->FLT = 4; - +} + +uint8_t twi2c_write(uint8_t data) { + uint8_t buffer[1] = {0}; + return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, &data, 1, buffer, 1, MS2ST(100)); +} + +uint8_t twi2c_transmit(uint8_t address, uint8_t* data, uint16_t length) { + twi2c_address = address; + i2cStart(&I2C_DRIVER, &I2CConfig); + return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, data, length, buffer, 1, MS2ST(100)); } diff --git a/drivers/arm/twi2c.h b/drivers/arm/twi2c.h index bc7a064a58..0f46cf6e28 100644 --- a/drivers/arm/twi2c.h +++ b/drivers/arm/twi2c.h @@ -28,4 +28,13 @@ I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; void twi2c_slave_init(void); -void twi2c_master_init(void); +void twi2c_init(void); +uint8_t twi2c_start(uint8_t address); +uint8_t twi2c_write(uint8_t data); +uint8_t twi2c_read_ack(void); +uint8_t twi2c_read_nack(void); +uint8_t twi2c_transmit(uint8_t address, uint8_t* data, uint16_t length); +uint8_t twi2c_receive(uint8_t address, uint8_t* data, uint16_t length); +uint8_t twi2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length); +uint8_t twi2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length); +void twi2c_stop(void); diff --git a/keyboards/_qmk_handwire/matrix.c b/keyboards/_qmk_handwire/matrix.c index 499c92f8ca..8999c1ee56 100644 --- a/keyboards/_qmk_handwire/matrix.c +++ b/keyboards/_qmk_handwire/matrix.c @@ -59,7 +59,7 @@ void matrix_init(void) { master = right_hand; if (master) { - twi2c_master_init(); + twi2c_init(); } else { twi2c_slave_init(); } diff --git a/lib/chibios b/lib/chibios index f9643c88ad..587968d6cb 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit f9643c88ad5cd0704d57bed83fe64f45b3e6be4e +Subproject commit 587968d6cbc2b0e1c7147540872f2a67e59ca18b From 874f5a5c076bd96fa97d7169187c50e13c065876 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 1 Jun 2018 11:31:29 -0400 Subject: [PATCH 36/42] mostly compiling --- common_features.mk | 2 +- drivers/arm/is31fl3731.c | 4 +- drivers/arm/twi2c.c | 18 +- drivers/arm/twi2c.h | 4 + keyboards/planck/light/light.c | 2 + keyboards/planck/light/{ => rev1}/config.h | 0 keyboards/planck/light/{ => rev1}/rules.mk | 0 .../rev2/boards/GENERIC_STM32_F303XC/board.c | 126 ++ .../rev2/boards/GENERIC_STM32_F303XC/board.h | 1187 +++++++++++++++++ .../rev2/boards/GENERIC_STM32_F303XC/board.mk | 5 + keyboards/planck/light/rev2/bootloader_defs.h | 7 + keyboards/planck/light/rev2/chconf.h | 520 ++++++++ keyboards/planck/light/rev2/config.h | 143 ++ keyboards/planck/light/rev2/halconf.h | 388 ++++++ keyboards/planck/light/rev2/matrix.c | 191 +++ keyboards/planck/light/rev2/mcuconf.h | 257 ++++ keyboards/planck/light/rev2/rev2.c | 24 + keyboards/planck/light/rev2/rev2.h | 21 + keyboards/planck/light/rev2/rules.mk | 56 + keyboards/planck/rev6/matrix.c | 7 +- 20 files changed, 2955 insertions(+), 7 deletions(-) rename keyboards/planck/light/{ => rev1}/config.h (100%) rename keyboards/planck/light/{ => rev1}/rules.mk (100%) create mode 100644 keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.c create mode 100644 keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.h create mode 100644 keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.mk create mode 100644 keyboards/planck/light/rev2/bootloader_defs.h create mode 100644 keyboards/planck/light/rev2/chconf.h create mode 100644 keyboards/planck/light/rev2/config.h create mode 100644 keyboards/planck/light/rev2/halconf.h create mode 100644 keyboards/planck/light/rev2/matrix.c create mode 100644 keyboards/planck/light/rev2/mcuconf.h create mode 100644 keyboards/planck/light/rev2/rev2.c create mode 100644 keyboards/planck/light/rev2/rev2.h create mode 100644 keyboards/planck/light/rev2/rules.mk diff --git a/common_features.mk b/common_features.mk index 6a09008ff2..c1f8421c88 100644 --- a/common_features.mk +++ b/common_features.mk @@ -123,7 +123,7 @@ endif ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) OPT_DEFS += -DRGB_MATRIX_ENABLE SRC += is31fl3731.c - SRC += i2c_master.c + SRC += twi2c.c SRC += $(QUANTUM_DIR)/color.c SRC += $(QUANTUM_DIR)/rgb_matrix.c CIE1931_CURVE = yes diff --git a/drivers/arm/is31fl3731.c b/drivers/arm/is31fl3731.c index f815ef94c5..4cf0c09f67 100644 --- a/drivers/arm/is31fl3731.c +++ b/drivers/arm/is31fl3731.c @@ -16,7 +16,7 @@ */ #include "is31fl3731.h" -#include +#include "wait.h" #include #include "twi2c.h" #include "progmem.h" @@ -123,7 +123,7 @@ void IS31FL3731_init( uint8_t addr ) // enable software shutdown IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x00 ); // this delay was copied from other drivers, might not be needed - _delay_ms( 10 ); + wait_ms( 10 ); // picture mode IS31FL3731_write_register( addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE ); diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 08d23b6160..9a08213833 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -17,12 +17,15 @@ #include "twi2c.h" #include #include -#include "hal_i2cslave.h" #include "chprintf.h" #include "memstreams.h" #include "printf.h" #include "matrix.h" +#ifdef I2C_SLAVE_ENABLE + +#include "hal_i2cslave.h" + /** * I2C slave test routine. * @@ -39,6 +42,8 @@ I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; +#endif + static uint8_t twi2c_address; static const I2CConfig I2CConfig = { @@ -60,6 +65,9 @@ uint8_t txBody[MATRIX_ROWS/2]; /* Return message buffer f BaseSequentialStream *chp = NULL; // Used for serial logging + +#ifdef I2C_SLAVE_ENABLE + // Handler when something sent to us const I2CSlaveMsg echoRx = { @@ -102,6 +110,7 @@ I2CSlaveMsg echoReply = { /* this is in RAM so size may be updated */ }; + /** * Track I2C errors */ @@ -131,6 +140,8 @@ extern void matrix_copy(matrix_row_t * copy); const char hexString[16] = "0123456789abcdef"; + + /** * Message processor - looks at received message, determines reply as quickly as possible * @@ -198,6 +209,8 @@ void twi2c_slave_task(void) { } } +#endif + uint8_t twi2c_start(uint8_t address) { twi2c_address = address; i2cStart(&I2C_DRIVER, &I2CConfig); @@ -216,8 +229,9 @@ void twi2c_init(void) { // I2C_DRIVER.i2c->FLT = 4; } +uint8_t buffer[1] = {0}; + uint8_t twi2c_write(uint8_t data) { - uint8_t buffer[1] = {0}; return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, &data, 1, buffer, 1, MS2ST(100)); } diff --git a/drivers/arm/twi2c.h b/drivers/arm/twi2c.h index 0f46cf6e28..57cc54070e 100644 --- a/drivers/arm/twi2c.h +++ b/drivers/arm/twi2c.h @@ -24,10 +24,14 @@ #define slaveI2Caddress 0x30 /* Address in our terms - halved by later code */ //#define myOtherI2Caddress 0x19 +#ifdef I2C_SLAVE_ENABLE + I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; void twi2c_slave_init(void); +#endif + void twi2c_init(void); uint8_t twi2c_start(uint8_t address); uint8_t twi2c_write(uint8_t data); diff --git a/keyboards/planck/light/light.c b/keyboards/planck/light/light.c index cef57c5e69..ccf75d50f2 100644 --- a/keyboards/planck/light/light.c +++ b/keyboards/planck/light/light.c @@ -140,8 +140,10 @@ const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { void matrix_init_kb(void) { // Turn status LED on + #ifdef KEYBOARD_planck_light_rev1 DDRD |= (1<<6); PORTD |= (1<<6); + #endif matrix_init_user(); } diff --git a/keyboards/planck/light/config.h b/keyboards/planck/light/rev1/config.h similarity index 100% rename from keyboards/planck/light/config.h rename to keyboards/planck/light/rev1/config.h diff --git a/keyboards/planck/light/rules.mk b/keyboards/planck/light/rev1/rules.mk similarity index 100% rename from keyboards/planck/light/rules.mk rename to keyboards/planck/light/rev1/rules.mk diff --git a/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.c b/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.c new file mode 100644 index 0000000000..4331155df4 --- /dev/null +++ b/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.c @@ -0,0 +1,126 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "hal.h" + +#if HAL_USE_PAL || defined(__DOXYGEN__) +/** + * @brief PAL setup. + * @details Digital I/O ports static configuration as defined in @p board.h. + * This variable is used by the HAL when initializing the PAL driver. + */ +const PALConfig pal_default_config = { +#if STM32_HAS_GPIOA + {VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR, + VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH}, +#endif +#if STM32_HAS_GPIOB + {VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR, + VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH}, +#endif +#if STM32_HAS_GPIOC + {VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR, + VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH}, +#endif +#if STM32_HAS_GPIOD + {VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR, + VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH}, +#endif +#if STM32_HAS_GPIOE + {VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR, + VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH}, +#endif +#if STM32_HAS_GPIOF + {VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR, + VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH}, +#endif +#if STM32_HAS_GPIOG + {VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR, + VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH}, +#endif +#if STM32_HAS_GPIOH + {VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR, + VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH}, +#endif +#if STM32_HAS_GPIOI + {VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR, + VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH} +#endif +}; +#endif + +void enter_bootloader_mode_if_requested(void); + +/** + * @brief Early initialization code. + * @details This initialization must be performed just after stack setup + * and before any other initialization. + */ +void __early_init(void) { + enter_bootloader_mode_if_requested(); + stm32_clock_init(); +} + +#if HAL_USE_SDC || defined(__DOXYGEN__) +/** + * @brief SDC card detection. + */ +bool sdc_lld_is_card_inserted(SDCDriver *sdcp) { + + (void)sdcp; + /* TODO: Fill the implementation.*/ + return true; +} + +/** + * @brief SDC card write protection detection. + */ +bool sdc_lld_is_write_protected(SDCDriver *sdcp) { + + (void)sdcp; + /* TODO: Fill the implementation.*/ + return false; +} +#endif /* HAL_USE_SDC */ + +#if HAL_USE_MMC_SPI || defined(__DOXYGEN__) +/** + * @brief MMC_SPI card detection. + */ +bool mmc_lld_is_card_inserted(MMCDriver *mmcp) { + + (void)mmcp; + /* TODO: Fill the implementation.*/ + return true; +} + +/** + * @brief MMC_SPI card write protection detection. + */ +bool mmc_lld_is_write_protected(MMCDriver *mmcp) { + + (void)mmcp; + /* TODO: Fill the implementation.*/ + return false; +} +#endif + +/** + * @brief Board-specific initialization code. + * @todo Add your board-specific code, if any. + */ +void boardInit(void) { +} diff --git a/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.h b/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.h new file mode 100644 index 0000000000..ec26557f3a --- /dev/null +++ b/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.h @@ -0,0 +1,1187 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef _BOARD_H_ +#define _BOARD_H_ + +/* + * Setup for Clueboard 60% Keyboard + */ + +/* + * Board identifier. + */ +#define BOARD_GENERIC_STM32_F303XC +#define BOARD_NAME "Planck PCB" + +/* + * Board oscillators-related settings. + * NOTE: LSE not fitted. + */ +#if !defined(STM32_LSECLK) +#define STM32_LSECLK 0U +#endif + +#define STM32_LSEDRV (3U << 3U) + +#if !defined(STM32_HSECLK) +#define STM32_HSECLK 8000000U +#endif + +// #define STM32_HSE_BYPASS + +/* + * MCU type as defined in the ST header. + */ +#define STM32F303xC + +/* + * IO pins assignments. + */ +#define GPIOA_PIN0 0U +#define GPIOA_PIN1 1U +#define GPIOA_PIN2 2U +#define GPIOA_PIN3 3U +#define GPIOA_PIN4 4U +#define GPIOA_PIN5 5U +#define GPIOA_PIN6 6U +#define GPIOA_PIN7 7U +#define GPIOA_PIN8 8U +#define GPIOA_PIN9 9U +#define GPIOA_PIN10 10U +#define GPIOA_USB_DM 11U +#define GPIOA_USB_DP 12U +#define GPIOA_SWDIO 13U +#define GPIOA_SWCLK 14U +#define GPIOA_PIN15 15U + +#define GPIOB_PIN0 0U +#define GPIOB_PIN1 1U +#define GPIOB_PIN2 2U +#define GPIOB_PIN3 3U +#define GPIOB_PIN4 4U +#define GPIOB_PIN5 5U +#define GPIOB_PIN6 6U +#define GPIOB_PIN7 7U +#define GPIOB_PIN8 8U +#define GPIOB_PIN9 9U +#define GPIOB_PIN10 10U +#define GPIOB_PIN11 11U +#define GPIOB_PIN12 12U +#define GPIOB_PIN13 13U +#define GPIOB_PIN14 14U +#define GPIOB_PIN15 15U + +#define GPIOC_PIN0 0U +#define GPIOC_PIN1 1U +#define GPIOC_PIN2 2U +#define GPIOC_PIN3 3U +#define GPIOC_PIN4 4U +#define GPIOC_PIN5 5U +#define GPIOC_PIN6 6U +#define GPIOC_PIN7 7U +#define GPIOC_PIN8 8U +#define GPIOC_PIN9 9U +#define GPIOC_PIN10 10U +#define GPIOC_PIN11 11U +#define GPIOC_PIN12 12U +#define GPIOC_PIN13 13U +#define GPIOC_PIN14 14U +#define GPIOC_PIN15 15U + +#define GPIOD_PIN0 0U +#define GPIOD_PIN1 1U +#define GPIOD_PIN2 2U +#define GPIOD_PIN3 3U +#define GPIOD_PIN4 4U +#define GPIOD_PIN5 5U +#define GPIOD_PIN6 6U +#define GPIOD_PIN7 7U +#define GPIOD_PIN8 8U +#define GPIOD_PIN9 9U +#define GPIOD_PIN10 10U +#define GPIOD_PIN11 11U +#define GPIOD_PIN12 12U +#define GPIOD_PIN13 13U +#define GPIOD_PIN14 14U +#define GPIOD_PIN15 15U + +#define GPIOE_PIN0 0U +#define GPIOE_PIN1 1U +#define GPIOE_PIN2 2U +#define GPIOE_PIN3 3U +#define GPIOE_PIN4 4U +#define GPIOE_PIN5 5U +#define GPIOE_PIN6 6U +#define GPIOE_PIN7 7U +#define GPIOE_PIN8 8U +#define GPIOE_PIN9 9U +#define GPIOE_PIN10 10U +#define GPIOE_PIN11 11U +#define GPIOE_PIN12 12U +#define GPIOE_PIN13 13U +#define GPIOE_PIN14 14U +#define GPIOE_PIN15 15U + +#define GPIOF_I2C2_SDA 0U +#define GPIOF_I2C2_SCL 1U +#define GPIOF_PIN2 2U +#define GPIOF_PIN3 3U +#define GPIOF_PIN4 4U +#define GPIOF_PIN5 5U +#define GPIOF_PIN6 6U +#define GPIOF_PIN7 7U +#define GPIOF_PIN8 8U +#define GPIOF_PIN9 9U +#define GPIOF_PIN10 10U +#define GPIOF_PIN11 11U +#define GPIOF_PIN12 12U +#define GPIOF_PIN13 13U +#define GPIOF_PIN14 14U +#define GPIOF_PIN15 15U + +#define GPIOG_PIN0 0U +#define GPIOG_PIN1 1U +#define GPIOG_PIN2 2U +#define GPIOG_PIN3 3U +#define GPIOG_PIN4 4U +#define GPIOG_PIN5 5U +#define GPIOG_PIN6 6U +#define GPIOG_PIN7 7U +#define GPIOG_PIN8 8U +#define GPIOG_PIN9 9U +#define GPIOG_PIN10 10U +#define GPIOG_PIN11 11U +#define GPIOG_PIN12 12U +#define GPIOG_PIN13 13U +#define GPIOG_PIN14 14U +#define GPIOG_PIN15 15U + +#define GPIOH_PIN0 0U +#define GPIOH_PIN1 1U +#define GPIOH_PIN2 2U +#define GPIOH_PIN3 3U +#define GPIOH_PIN4 4U +#define GPIOH_PIN5 5U +#define GPIOH_PIN6 6U +#define GPIOH_PIN7 7U +#define GPIOH_PIN8 8U +#define GPIOH_PIN9 9U +#define GPIOH_PIN10 10U +#define GPIOH_PIN11 11U +#define GPIOH_PIN12 12U +#define GPIOH_PIN13 13U +#define GPIOH_PIN14 14U +#define GPIOH_PIN15 15U + +/* + * IO lines assignments. + */ +#define LINE_L3GD20_SDI PAL_LINE(GPIOA, 7U) +#define LINE_USB_DM PAL_LINE(GPIOA, 11U) +#define LINE_USB_DP PAL_LINE(GPIOA, 12U) +#define LINE_SWDIO PAL_LINE(GPIOA, 13U) +#define LINE_SWCLK PAL_LINE(GPIOA, 14U) + +#define LINE_PIN6 PAL_LINE(GPIOF, 0U) +#define LINE_PIN7 PAL_LINE(GPIOF, 1U) + +#define LINE_CAPS_LOCK PAL_LINE(GPIOB, 7U) + + +/* + * I/O ports initial setup, this configuration is established soon after reset + * in the initialization code. + * Please refer to the STM32 Reference Manual for details. + */ +#define PIN_MODE_INPUT(n) (0U << ((n) * 2U)) +#define PIN_MODE_OUTPUT(n) (1U << ((n) * 2U)) +#define PIN_MODE_ALTERNATE(n) (2U << ((n) * 2U)) +#define PIN_MODE_ANALOG(n) (3U << ((n) * 2U)) +#define PIN_ODR_LOW(n) (0U << (n)) +#define PIN_ODR_HIGH(n) (1U << (n)) +#define PIN_OTYPE_PUSHPULL(n) (0U << (n)) +#define PIN_OTYPE_OPENDRAIN(n) (1U << (n)) +#define PIN_OSPEED_VERYLOW(n) (0U << ((n) * 2U)) +#define PIN_OSPEED_LOW(n) (1U << ((n) * 2U)) +#define PIN_OSPEED_MEDIUM(n) (2U << ((n) * 2U)) +#define PIN_OSPEED_HIGH(n) (3U << ((n) * 2U)) +#define PIN_PUPDR_FLOATING(n) (0U << ((n) * 2U)) +#define PIN_PUPDR_PULLUP(n) (1U << ((n) * 2U)) +#define PIN_PUPDR_PULLDOWN(n) (2U << ((n) * 2U)) +#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U)) + +/* + * GPIOA setup: + * + * PA0 - NC + * PA1 - NC + * PA2 - COL1 + * PA3 - COL2 + * PA4 - SPEAKER1 + * PA5 - SPEAKER2 + * PA6 - COL3 + * PA7 - COL8 + * PA8 - COL6 + * PA9 - COL7 + * PA10 - ROW5 + * PA11 - USB_DM (alternate 14). + * PA12 - USB_DP (alternate 14). + * PA13 - SWDIO (alternate 0). + * PA14 - SWCLK (alternate 0). + * PA15 - ROW4 + */ +#define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_PIN0) | \ + PIN_MODE_ALTERNATE(GPIOA_PIN1) | \ + PIN_MODE_INPUT(GPIOA_PIN2) | \ + PIN_MODE_INPUT(GPIOA_PIN3) | \ + PIN_MODE_INPUT(GPIOA_PIN4) | \ + PIN_MODE_INPUT(GPIOA_PIN5) | \ + PIN_MODE_INPUT(GPIOA_PIN6) | \ + PIN_MODE_INPUT(GPIOA_PIN7) | \ + PIN_MODE_INPUT(GPIOA_PIN8) | \ + PIN_MODE_INPUT(GPIOA_PIN9) | \ + PIN_MODE_INPUT(GPIOA_PIN10) | \ + PIN_MODE_ALTERNATE(GPIOA_USB_DM) | \ + PIN_MODE_ALTERNATE(GPIOA_USB_DP) | \ + PIN_MODE_ALTERNATE(GPIOA_SWDIO) | \ + PIN_MODE_ALTERNATE(GPIOA_SWCLK) | \ + PIN_MODE_INPUT(GPIOA_PIN15)) +#define VAL_GPIOA_OTYPER (PIN_OTYPE_PUSHPULL(GPIOA_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOA_USB_DM) | \ + PIN_OTYPE_PUSHPULL(GPIOA_USB_DP) | \ + PIN_OTYPE_PUSHPULL(GPIOA_SWDIO) | \ + PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) | \ + PIN_OTYPE_PUSHPULL(GPIOA_PIN15)) +#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOA_PIN0) | \ + PIN_OSPEED_HIGH(GPIOA_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN10) | \ + PIN_OSPEED_HIGH(GPIOA_USB_DM) | \ + PIN_OSPEED_VERYLOW(GPIOA_USB_DP) | \ + PIN_OSPEED_HIGH(GPIOA_SWDIO) | \ + PIN_OSPEED_HIGH(GPIOA_SWCLK) | \ + PIN_OSPEED_VERYLOW(GPIOA_PIN15)) +#define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_PIN0) | \ + PIN_PUPDR_FLOATING(GPIOA_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN6) | \ + PIN_PUPDR_FLOATING(GPIOA_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN10) | \ + PIN_PUPDR_FLOATING(GPIOA_USB_DM) | \ + PIN_PUPDR_FLOATING(GPIOA_USB_DP) | \ + PIN_PUPDR_PULLUP(GPIOA_SWDIO) | \ + PIN_PUPDR_PULLDOWN(GPIOA_SWCLK) | \ + PIN_PUPDR_PULLUP(GPIOA_PIN15)) +#define VAL_GPIOA_ODR (PIN_ODR_HIGH(GPIOA_PIN0) | \ + PIN_ODR_HIGH(GPIOA_PIN1) | \ + PIN_ODR_HIGH(GPIOA_PIN2) | \ + PIN_ODR_HIGH(GPIOA_PIN3) | \ + PIN_ODR_HIGH(GPIOA_PIN4) | \ + PIN_ODR_HIGH(GPIOA_PIN5) | \ + PIN_ODR_HIGH(GPIOA_PIN6) | \ + PIN_ODR_HIGH(GPIOA_PIN7) | \ + PIN_ODR_HIGH(GPIOA_PIN8) | \ + PIN_ODR_HIGH(GPIOA_PIN9) | \ + PIN_ODR_HIGH(GPIOA_PIN10) | \ + PIN_ODR_HIGH(GPIOA_USB_DM) | \ + PIN_ODR_HIGH(GPIOA_USB_DP) | \ + PIN_ODR_HIGH(GPIOA_SWDIO) | \ + PIN_ODR_HIGH(GPIOA_SWCLK) | \ + PIN_ODR_HIGH(GPIOA_PIN15)) +#define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PIN0, 0) | \ + PIN_AFIO_AF(GPIOA_PIN1, 1) | \ + PIN_AFIO_AF(GPIOA_PIN2, 0) | \ + PIN_AFIO_AF(GPIOA_PIN3, 0) | \ + PIN_AFIO_AF(GPIOA_PIN4, 0) | \ + PIN_AFIO_AF(GPIOA_PIN5, 5) | \ + PIN_AFIO_AF(GPIOA_PIN6, 5) | \ + PIN_AFIO_AF(GPIOA_PIN7, 5)) +#define VAL_GPIOA_AFRH (PIN_AFIO_AF(GPIOA_PIN8, 0) | \ + PIN_AFIO_AF(GPIOA_PIN9, 0) | \ + PIN_AFIO_AF(GPIOA_PIN10, 0) | \ + PIN_AFIO_AF(GPIOA_USB_DM, 14) | \ + PIN_AFIO_AF(GPIOA_USB_DP, 14) | \ + PIN_AFIO_AF(GPIOA_SWDIO, 0) | \ + PIN_AFIO_AF(GPIOA_SWCLK, 0) | \ + PIN_AFIO_AF(GPIOA_PIN15, 0)) + +/* + * GPIOB setup: + * + * PB0 - PIN0 (input pullup). + * PB1 - PIN1 (input pullup). + * PB2 - PIN2 (input pullup). + * PB3 - PIN3 (alternate 0). + * PB4 - PIN4 (input pullup). + * PB5 - PIN5 (input pullup). + * PB6 - PIN6 LSM303DLHC_SCL (alternate 4). + * PB7 - PIN7 LSM303DLHC_SDA (alternate 4). + * PB8 - PIN8 (input pullup). + * PB9 - PIN9 (input pullup). + * PB10 - PIN10 (input pullup). + * PB11 - PIN11 (input pullup). + * PB12 - PIN12 (input pullup). + * PB13 - PIN13 (input pullup). + * PB14 - PIN14 (input pullup). + * PB15 - PIN15 (input pullup). + */ +#define VAL_GPIOB_MODER (PIN_MODE_INPUT(GPIOB_PIN0) | \ + PIN_MODE_INPUT(GPIOB_PIN1) | \ + PIN_MODE_INPUT(GPIOB_PIN2) | \ + PIN_MODE_ALTERNATE(GPIOB_PIN3) | \ + PIN_MODE_INPUT(GPIOB_PIN4) | \ + PIN_MODE_INPUT(GPIOB_PIN5) | \ + PIN_MODE_ALTERNATE(GPIOB_PIN6) | \ + PIN_MODE_OUTPUT(GPIOB_PIN7) | \ + PIN_MODE_INPUT(GPIOB_PIN8) | \ + PIN_MODE_INPUT(GPIOB_PIN9) | \ + PIN_MODE_INPUT(GPIOB_PIN10) | \ + PIN_MODE_INPUT(GPIOB_PIN11) | \ + PIN_MODE_INPUT(GPIOB_PIN12) | \ + PIN_MODE_INPUT(GPIOB_PIN13) | \ + PIN_MODE_INPUT(GPIOB_PIN14) | \ + PIN_MODE_INPUT(GPIOB_PIN15)) +#define VAL_GPIOB_OTYPER (PIN_OTYPE_PUSHPULL(GPIOB_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN5) | \ + PIN_OTYPE_OPENDRAIN(GPIOB_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOB_PIN15)) +#define VAL_GPIOB_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOB_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN2) | \ + PIN_OSPEED_HIGH(GPIOB_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN5) | \ + PIN_OSPEED_HIGH(GPIOB_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOB_PIN15)) +#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLUP(GPIOB_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN2) | \ + PIN_PUPDR_FLOATING(GPIOB_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN5) | \ + PIN_PUPDR_FLOATING(GPIOB_PIN6) | \ + PIN_PUPDR_PULLDOWN(GPIOB_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOB_PIN15)) +#define VAL_GPIOB_ODR (PIN_ODR_HIGH(GPIOB_PIN0) | \ + PIN_ODR_HIGH(GPIOB_PIN1) | \ + PIN_ODR_HIGH(GPIOB_PIN2) | \ + PIN_ODR_HIGH(GPIOB_PIN3) | \ + PIN_ODR_HIGH(GPIOB_PIN4) | \ + PIN_ODR_HIGH(GPIOB_PIN5) | \ + PIN_ODR_HIGH(GPIOB_PIN6) | \ + PIN_ODR_LOW(GPIOB_PIN7) | \ + PIN_ODR_HIGH(GPIOB_PIN8) | \ + PIN_ODR_HIGH(GPIOB_PIN9) | \ + PIN_ODR_HIGH(GPIOB_PIN10) | \ + PIN_ODR_HIGH(GPIOB_PIN11) | \ + PIN_ODR_HIGH(GPIOB_PIN12) | \ + PIN_ODR_HIGH(GPIOB_PIN13) | \ + PIN_ODR_HIGH(GPIOB_PIN14) | \ + PIN_ODR_HIGH(GPIOB_PIN15)) +#define VAL_GPIOB_AFRL (PIN_AFIO_AF(GPIOB_PIN0, 0) | \ + PIN_AFIO_AF(GPIOB_PIN1, 0) | \ + PIN_AFIO_AF(GPIOB_PIN2, 0) | \ + PIN_AFIO_AF(GPIOB_PIN3, 0) | \ + PIN_AFIO_AF(GPIOB_PIN4, 0) | \ + PIN_AFIO_AF(GPIOB_PIN5, 0) | \ + PIN_AFIO_AF(GPIOB_PIN6, 4) | \ + PIN_AFIO_AF(GPIOB_PIN7, 0)) +#define VAL_GPIOB_AFRH (PIN_AFIO_AF(GPIOB_PIN8, 0) | \ + PIN_AFIO_AF(GPIOB_PIN9, 0) | \ + PIN_AFIO_AF(GPIOB_PIN10, 0) | \ + PIN_AFIO_AF(GPIOB_PIN11, 0) | \ + PIN_AFIO_AF(GPIOB_PIN12, 0) | \ + PIN_AFIO_AF(GPIOB_PIN13, 0) | \ + PIN_AFIO_AF(GPIOB_PIN14, 0) | \ + PIN_AFIO_AF(GPIOB_PIN15, 0)) + +/* + * GPIOC setup: + * + * PC0 - PIN0 (input pullup). + * PC1 - PIN1 (input pullup). + * PC2 - PIN2 (input pullup). + * PC3 - PIN3 (input pullup). + * PC4 - PIN4 (input pullup). + * PC5 - PIN5 (input pullup). + * PC6 - PIN6 (input pullup). + * PC7 - PIN7 (input pullup). + * PC8 - PIN8 (input pullup). + * PC9 - PIN9 (input pullup). + * PC10 - PIN10 (input pullup). + * PC11 - PIN11 (input pullup). + * PC12 - PIN12 (input pullup). + * PC13 - PIN13 (input pullup). + * PC14 - PIN14 (input floating). + * PC15 - PIN15 (input floating). + */ +#define VAL_GPIOC_MODER (PIN_MODE_INPUT(GPIOC_PIN0) | \ + PIN_MODE_INPUT(GPIOC_PIN1) | \ + PIN_MODE_INPUT(GPIOC_PIN2) | \ + PIN_MODE_INPUT(GPIOC_PIN3) | \ + PIN_MODE_INPUT(GPIOC_PIN4) | \ + PIN_MODE_INPUT(GPIOC_PIN5) | \ + PIN_MODE_INPUT(GPIOC_PIN6) | \ + PIN_MODE_INPUT(GPIOC_PIN7) | \ + PIN_MODE_INPUT(GPIOC_PIN8) | \ + PIN_MODE_INPUT(GPIOC_PIN9) | \ + PIN_MODE_INPUT(GPIOC_PIN10) | \ + PIN_MODE_INPUT(GPIOC_PIN11) | \ + PIN_MODE_INPUT(GPIOC_PIN12) | \ + PIN_MODE_INPUT(GPIOC_PIN13) | \ + PIN_MODE_INPUT(GPIOC_PIN14) | \ + PIN_MODE_INPUT(GPIOC_PIN15)) +#define VAL_GPIOC_OTYPER (PIN_OTYPE_PUSHPULL(GPIOC_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOC_PIN15)) +#define VAL_GPIOC_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOC_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOC_PIN13) | \ + PIN_OSPEED_HIGH(GPIOC_PIN14) | \ + PIN_OSPEED_HIGH(GPIOC_PIN15)) +#define VAL_GPIOC_PUPDR (PIN_PUPDR_PULLUP(GPIOC_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOC_PIN13) | \ + PIN_PUPDR_FLOATING(GPIOC_PIN14) | \ + PIN_PUPDR_FLOATING(GPIOC_PIN15)) +#define VAL_GPIOC_ODR (PIN_ODR_HIGH(GPIOC_PIN0) | \ + PIN_ODR_HIGH(GPIOC_PIN1) | \ + PIN_ODR_HIGH(GPIOC_PIN2) | \ + PIN_ODR_HIGH(GPIOC_PIN3) | \ + PIN_ODR_HIGH(GPIOC_PIN4) | \ + PIN_ODR_HIGH(GPIOC_PIN5) | \ + PIN_ODR_HIGH(GPIOC_PIN6) | \ + PIN_ODR_HIGH(GPIOC_PIN7) | \ + PIN_ODR_HIGH(GPIOC_PIN8) | \ + PIN_ODR_HIGH(GPIOC_PIN9) | \ + PIN_ODR_HIGH(GPIOC_PIN10) | \ + PIN_ODR_HIGH(GPIOC_PIN11) | \ + PIN_ODR_HIGH(GPIOC_PIN12) | \ + PIN_ODR_HIGH(GPIOC_PIN13) | \ + PIN_ODR_HIGH(GPIOC_PIN14) | \ + PIN_ODR_HIGH(GPIOC_PIN15)) +#define VAL_GPIOC_AFRL (PIN_AFIO_AF(GPIOC_PIN0, 0) | \ + PIN_AFIO_AF(GPIOC_PIN1, 0) | \ + PIN_AFIO_AF(GPIOC_PIN2, 0) | \ + PIN_AFIO_AF(GPIOC_PIN3, 0) | \ + PIN_AFIO_AF(GPIOC_PIN4, 0) | \ + PIN_AFIO_AF(GPIOC_PIN5, 0) | \ + PIN_AFIO_AF(GPIOC_PIN6, 0) | \ + PIN_AFIO_AF(GPIOC_PIN7, 0)) +#define VAL_GPIOC_AFRH (PIN_AFIO_AF(GPIOC_PIN8, 0) | \ + PIN_AFIO_AF(GPIOC_PIN9, 0) | \ + PIN_AFIO_AF(GPIOC_PIN10, 0) | \ + PIN_AFIO_AF(GPIOC_PIN11, 0) | \ + PIN_AFIO_AF(GPIOC_PIN12, 0) | \ + PIN_AFIO_AF(GPIOC_PIN13, 0) | \ + PIN_AFIO_AF(GPIOC_PIN14, 0) | \ + PIN_AFIO_AF(GPIOC_PIN15, 0)) + +/* + * GPIOD setup: + * + * PD0 - PIN0 (input pullup). + * PD1 - PIN1 (input pullup). + * PD2 - PIN2 (input pullup). + * PD3 - PIN3 (input pullup). + * PD4 - PIN4 (input pullup). + * PD5 - PIN5 (input pullup). + * PD6 - PIN6 (input pullup). + * PD7 - PIN7 (input pullup). + * PD8 - PIN8 (input pullup). + * PD9 - PIN9 (input pullup). + * PD11 - PIN10 (input pullup). + * PD11 - PIN11 (input pullup). + * PD12 - PIN12 (input pullup). + * PD13 - PIN13 (input pullup). + * PD14 - PIN14 (input pullup). + * PD15 - PIN15 (input pullup). + */ +#define VAL_GPIOD_MODER (PIN_MODE_INPUT(GPIOD_PIN0) | \ + PIN_MODE_INPUT(GPIOD_PIN1) | \ + PIN_MODE_INPUT(GPIOD_PIN2) | \ + PIN_MODE_INPUT(GPIOD_PIN3) | \ + PIN_MODE_INPUT(GPIOD_PIN4) | \ + PIN_MODE_INPUT(GPIOD_PIN5) | \ + PIN_MODE_INPUT(GPIOD_PIN6) | \ + PIN_MODE_INPUT(GPIOD_PIN7) | \ + PIN_MODE_INPUT(GPIOD_PIN8) | \ + PIN_MODE_INPUT(GPIOD_PIN9) | \ + PIN_MODE_INPUT(GPIOD_PIN10) | \ + PIN_MODE_INPUT(GPIOD_PIN11) | \ + PIN_MODE_INPUT(GPIOD_PIN12) | \ + PIN_MODE_INPUT(GPIOD_PIN13) | \ + PIN_MODE_INPUT(GPIOD_PIN14) | \ + PIN_MODE_INPUT(GPIOD_PIN15)) +#define VAL_GPIOD_OTYPER (PIN_OTYPE_PUSHPULL(GPIOD_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOD_PIN15)) +#define VAL_GPIOD_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOD_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOD_PIN15)) +#define VAL_GPIOD_PUPDR (PIN_PUPDR_PULLUP(GPIOD_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOD_PIN15)) +#define VAL_GPIOD_ODR (PIN_ODR_HIGH(GPIOD_PIN0) | \ + PIN_ODR_HIGH(GPIOD_PIN1) | \ + PIN_ODR_HIGH(GPIOD_PIN2) | \ + PIN_ODR_HIGH(GPIOD_PIN3) | \ + PIN_ODR_HIGH(GPIOD_PIN4) | \ + PIN_ODR_HIGH(GPIOD_PIN5) | \ + PIN_ODR_HIGH(GPIOD_PIN6) | \ + PIN_ODR_HIGH(GPIOD_PIN7) | \ + PIN_ODR_HIGH(GPIOD_PIN8) | \ + PIN_ODR_HIGH(GPIOD_PIN9) | \ + PIN_ODR_HIGH(GPIOD_PIN10) | \ + PIN_ODR_HIGH(GPIOD_PIN11) | \ + PIN_ODR_HIGH(GPIOD_PIN12) | \ + PIN_ODR_HIGH(GPIOD_PIN13) | \ + PIN_ODR_HIGH(GPIOD_PIN14) | \ + PIN_ODR_HIGH(GPIOD_PIN15)) +#define VAL_GPIOD_AFRL (PIN_AFIO_AF(GPIOD_PIN0, 0) | \ + PIN_AFIO_AF(GPIOD_PIN1, 0) | \ + PIN_AFIO_AF(GPIOD_PIN2, 0) | \ + PIN_AFIO_AF(GPIOD_PIN3, 0) | \ + PIN_AFIO_AF(GPIOD_PIN4, 0) | \ + PIN_AFIO_AF(GPIOD_PIN5, 0) | \ + PIN_AFIO_AF(GPIOD_PIN6, 0) | \ + PIN_AFIO_AF(GPIOD_PIN7, 0)) +#define VAL_GPIOD_AFRH (PIN_AFIO_AF(GPIOD_PIN8, 0) | \ + PIN_AFIO_AF(GPIOD_PIN9, 0) | \ + PIN_AFIO_AF(GPIOD_PIN10, 0) | \ + PIN_AFIO_AF(GPIOD_PIN11, 0) | \ + PIN_AFIO_AF(GPIOD_PIN12, 0) | \ + PIN_AFIO_AF(GPIOD_PIN13, 0) | \ + PIN_AFIO_AF(GPIOD_PIN14, 0) | \ + PIN_AFIO_AF(GPIOD_PIN15, 0)) + +/* + * GPIOE setup: + * + * PE0 - PIN0 (input pullup). + * PE1 - PIN1 (input pullup). + * PE2 - PIN2 (input pullup). + * PE3 - PIN3 L3GD20_CS (output pushpull maximum). + * PE4 - PIN4 (input pullup). + * PE5 - PIN5 (input pullup). + * PE6 - PIN6 (input pullup). + * PE7 - PIN7 (input pullup). + * PE8 - PIN8 (output pushpull maximum). + * PE9 - PIN9 (output pushpull maximum). + * PE10 - PIN10 (output pushpull maximum). + * PE11 - PIN11 (output pushpull maximum). + * PE12 - PIN12 (output pushpull maximum). + * PE13 - PIN13 (output pushpull maximum). + * PE14 - PIN14 (output pushpull maximum). + * PE15 - PIN15 (output pushpull maximum). + */ +#define VAL_GPIOE_MODER (PIN_MODE_INPUT(GPIOE_PIN0) | \ + PIN_MODE_INPUT(GPIOE_PIN1) | \ + PIN_MODE_INPUT(GPIOE_PIN2) |\ + PIN_MODE_OUTPUT(GPIOE_PIN3) | \ + PIN_MODE_INPUT(GPIOE_PIN4) |\ + PIN_MODE_INPUT(GPIOE_PIN5) |\ + PIN_MODE_INPUT(GPIOE_PIN6) | \ + PIN_MODE_INPUT(GPIOE_PIN7) | \ + PIN_MODE_OUTPUT(GPIOE_PIN8) | \ + PIN_MODE_OUTPUT(GPIOE_PIN9) | \ + PIN_MODE_OUTPUT(GPIOE_PIN10) | \ + PIN_MODE_OUTPUT(GPIOE_PIN11) | \ + PIN_MODE_OUTPUT(GPIOE_PIN12) | \ + PIN_MODE_OUTPUT(GPIOE_PIN13) | \ + PIN_MODE_OUTPUT(GPIOE_PIN14) | \ + PIN_MODE_OUTPUT(GPIOE_PIN15)) +#define VAL_GPIOE_OTYPER (PIN_OTYPE_PUSHPULL(GPIOE_PIN0) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN1) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN2) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN4) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN5) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN10) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOE_PIN14) |\ + PIN_OTYPE_PUSHPULL(GPIOE_PIN15)) +#define VAL_GPIOE_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOE_PIN0) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN1) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN2) |\ + PIN_OSPEED_HIGH(GPIOE_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOE_PIN4) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN5) |\ + PIN_OSPEED_VERYLOW(GPIOE_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOE_PIN7) | \ + PIN_OSPEED_HIGH(GPIOE_PIN8) | \ + PIN_OSPEED_HIGH(GPIOE_PIN9) | \ + PIN_OSPEED_HIGH(GPIOE_PIN10) | \ + PIN_OSPEED_HIGH(GPIOE_PIN11) | \ + PIN_OSPEED_HIGH(GPIOE_PIN12) | \ + PIN_OSPEED_HIGH(GPIOE_PIN13) | \ + PIN_OSPEED_HIGH(GPIOE_PIN14) | \ + PIN_OSPEED_HIGH(GPIOE_PIN15)) +#define VAL_GPIOE_PUPDR (PIN_PUPDR_PULLUP(GPIOE_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN2) |\ + PIN_PUPDR_FLOATING(GPIOE_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN4) |\ + PIN_PUPDR_PULLUP(GPIOE_PIN5) |\ + PIN_PUPDR_PULLUP(GPIOE_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN10) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOE_PIN12) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN13) | \ + PIN_PUPDR_FLOATING(GPIOE_PIN14) |\ + PIN_PUPDR_FLOATING(GPIOE_PIN15)) +#define VAL_GPIOE_ODR (PIN_ODR_HIGH(GPIOE_PIN0) | \ + PIN_ODR_HIGH(GPIOE_PIN1) | \ + PIN_ODR_HIGH(GPIOE_PIN2) | \ + PIN_ODR_HIGH(GPIOE_PIN3) | \ + PIN_ODR_HIGH(GPIOE_PIN4) | \ + PIN_ODR_HIGH(GPIOE_PIN5) | \ + PIN_ODR_HIGH(GPIOE_PIN6) | \ + PIN_ODR_HIGH(GPIOE_PIN7) | \ + PIN_ODR_LOW(GPIOE_PIN8) | \ + PIN_ODR_LOW(GPIOE_PIN9) | \ + PIN_ODR_LOW(GPIOE_PIN10) | \ + PIN_ODR_LOW(GPIOE_PIN11) | \ + PIN_ODR_LOW(GPIOE_PIN12) | \ + PIN_ODR_LOW(GPIOE_PIN13) | \ + PIN_ODR_LOW(GPIOE_PIN14) | \ + PIN_ODR_LOW(GPIOE_PIN15)) +#define VAL_GPIOE_AFRL (PIN_AFIO_AF(GPIOE_PIN0, 0) | \ + PIN_AFIO_AF(GPIOE_PIN1, 0) | \ + PIN_AFIO_AF(GPIOE_PIN2, 0) |\ + PIN_AFIO_AF(GPIOE_PIN3, 0) | \ + PIN_AFIO_AF(GPIOE_PIN4, 0) |\ + PIN_AFIO_AF(GPIOE_PIN5, 0) |\ + PIN_AFIO_AF(GPIOE_PIN6, 0) | \ + PIN_AFIO_AF(GPIOE_PIN7, 0)) +#define VAL_GPIOE_AFRH (PIN_AFIO_AF(GPIOE_PIN8, 0) | \ + PIN_AFIO_AF(GPIOE_PIN9, 0) | \ + PIN_AFIO_AF(GPIOE_PIN10, 0) | \ + PIN_AFIO_AF(GPIOE_PIN11, 0) | \ + PIN_AFIO_AF(GPIOE_PIN12, 0) | \ + PIN_AFIO_AF(GPIOE_PIN13, 0) | \ + PIN_AFIO_AF(GPIOE_PIN14, 0) | \ + PIN_AFIO_AF(GPIOE_PIN15, 0)) + +/* + * GPIOF setup: + * + * PF0 - I2C2_SDA (input floating). + * PF1 - I2C2_SCL (input floating). + * PF2 - PIN2 (input pullup). + * PF3 - PIN3 (input pullup). + * PF4 - PIN4 (input pullup). + * PF5 - PIN5 (input pullup). + * PF6 - PIN6 (input pullup). + * PF7 - PIN7 (input pullup). + * PF8 - PIN8 (input pullup). + * PF9 - PIN9 (input pullup). + * PF10 - PIN10 (input pullup). + * PF11 - PIN11 (input pullup). + * PF12 - PIN12 (input pullup). + * PF13 - PIN13 (input pullup). + * PF14 - PIN14 (input pullup). + * PF15 - PIN15 (input pullup). + */ +#define VAL_GPIOF_MODER (PIN_MODE_INPUT(GPIOF_I2C2_SDA) | \ + PIN_MODE_INPUT(GPIOF_I2C2_SCL) | \ + PIN_MODE_INPUT(GPIOF_PIN2) | \ + PIN_MODE_INPUT(GPIOF_PIN3) | \ + PIN_MODE_INPUT(GPIOF_PIN4) | \ + PIN_MODE_INPUT(GPIOF_PIN5) | \ + PIN_MODE_INPUT(GPIOF_PIN6) | \ + PIN_MODE_INPUT(GPIOF_PIN7) | \ + PIN_MODE_INPUT(GPIOF_PIN8) | \ + PIN_MODE_INPUT(GPIOF_PIN9) | \ + PIN_MODE_INPUT(GPIOF_PIN10) | \ + PIN_MODE_INPUT(GPIOF_PIN11) | \ + PIN_MODE_INPUT(GPIOF_PIN12) | \ + PIN_MODE_INPUT(GPIOF_PIN13) | \ + PIN_MODE_INPUT(GPIOF_PIN14) | \ + PIN_MODE_INPUT(GPIOF_PIN15)) +#define VAL_GPIOF_OTYPER (PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SDA) | \ + PIN_OTYPE_PUSHPULL(GPIOF_I2C2_SCL) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOF_PIN15)) +#define VAL_GPIOF_OSPEEDR (PIN_OSPEED_HIGH(GPIOF_I2C2_SDA) | \ + PIN_OSPEED_HIGH(GPIOF_I2C2_SCL) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOF_PIN15)) +#define VAL_GPIOF_PUPDR (PIN_PUPDR_FLOATING(GPIOF_I2C2_SDA) | \ + PIN_PUPDR_FLOATING(GPIOF_I2C2_SCL) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOF_PIN15)) +#define VAL_GPIOF_ODR (PIN_ODR_HIGH(GPIOF_I2C2_SDA) | \ + PIN_ODR_HIGH(GPIOF_I2C2_SCL) | \ + PIN_ODR_HIGH(GPIOF_PIN2) | \ + PIN_ODR_HIGH(GPIOF_PIN3) | \ + PIN_ODR_HIGH(GPIOF_PIN4) | \ + PIN_ODR_HIGH(GPIOF_PIN5) | \ + PIN_ODR_HIGH(GPIOF_PIN6) | \ + PIN_ODR_HIGH(GPIOF_PIN7) | \ + PIN_ODR_HIGH(GPIOF_PIN8) | \ + PIN_ODR_HIGH(GPIOF_PIN9) | \ + PIN_ODR_HIGH(GPIOF_PIN10) | \ + PIN_ODR_HIGH(GPIOF_PIN11) | \ + PIN_ODR_HIGH(GPIOF_PIN12) | \ + PIN_ODR_HIGH(GPIOF_PIN13) | \ + PIN_ODR_HIGH(GPIOF_PIN14) | \ + PIN_ODR_HIGH(GPIOF_PIN15)) +#define VAL_GPIOF_AFRL (PIN_AFIO_AF(GPIOF_I2C2_SDA, 0) | \ + PIN_AFIO_AF(GPIOF_I2C2_SCL, 0) | \ + PIN_AFIO_AF(GPIOF_PIN2, 0) | \ + PIN_AFIO_AF(GPIOF_PIN3, 0) | \ + PIN_AFIO_AF(GPIOF_PIN4, 0) | \ + PIN_AFIO_AF(GPIOF_PIN5, 0) | \ + PIN_AFIO_AF(GPIOF_PIN6, 0) | \ + PIN_AFIO_AF(GPIOF_PIN7, 0)) +#define VAL_GPIOF_AFRH (PIN_AFIO_AF(GPIOF_PIN8, 0) | \ + PIN_AFIO_AF(GPIOF_PIN9, 0) | \ + PIN_AFIO_AF(GPIOF_PIN10, 0) | \ + PIN_AFIO_AF(GPIOF_PIN11, 0) | \ + PIN_AFIO_AF(GPIOF_PIN12, 0) | \ + PIN_AFIO_AF(GPIOF_PIN13, 0) | \ + PIN_AFIO_AF(GPIOF_PIN14, 0) | \ + PIN_AFIO_AF(GPIOF_PIN15, 0)) + +/* + * GPIOG setup: + * + * PG0 - PIN0 (input pullup). + * PG1 - PIN1 (input pullup). + * PG2 - PIN2 (input pullup). + * PG3 - PIN3 (input pullup). + * PG4 - PIN4 (input pullup). + * PG5 - PIN5 (input pullup). + * PG6 - PIN6 (input pullup). + * PG7 - PIN7 (input pullup). + * PG8 - PIN8 (input pullup). + * PG9 - PIN9 (input pullup). + * PG10 - PIN10 (input pullup). + * PG11 - PIN11 (input pullup). + * PG12 - PIN12 (input pullup). + * PG13 - PIN13 (input pullup). + * PG14 - PIN14 (input pullup). + * PG15 - PIN15 (input pullup). + */ +#define VAL_GPIOG_MODER (PIN_MODE_INPUT(GPIOG_PIN0) | \ + PIN_MODE_INPUT(GPIOG_PIN1) | \ + PIN_MODE_INPUT(GPIOG_PIN2) | \ + PIN_MODE_INPUT(GPIOG_PIN3) | \ + PIN_MODE_INPUT(GPIOG_PIN4) | \ + PIN_MODE_INPUT(GPIOG_PIN5) | \ + PIN_MODE_INPUT(GPIOG_PIN6) | \ + PIN_MODE_INPUT(GPIOG_PIN7) | \ + PIN_MODE_INPUT(GPIOG_PIN8) | \ + PIN_MODE_INPUT(GPIOG_PIN9) | \ + PIN_MODE_INPUT(GPIOG_PIN10) | \ + PIN_MODE_INPUT(GPIOG_PIN11) | \ + PIN_MODE_INPUT(GPIOG_PIN12) | \ + PIN_MODE_INPUT(GPIOG_PIN13) | \ + PIN_MODE_INPUT(GPIOG_PIN14) | \ + PIN_MODE_INPUT(GPIOG_PIN15)) +#define VAL_GPIOG_OTYPER (PIN_OTYPE_PUSHPULL(GPIOG_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOG_PIN15)) +#define VAL_GPIOG_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOG_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOG_PIN15)) +#define VAL_GPIOG_PUPDR (PIN_PUPDR_PULLUP(GPIOG_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOG_PIN15)) +#define VAL_GPIOG_ODR (PIN_ODR_HIGH(GPIOG_PIN0) | \ + PIN_ODR_HIGH(GPIOG_PIN1) | \ + PIN_ODR_HIGH(GPIOG_PIN2) | \ + PIN_ODR_HIGH(GPIOG_PIN3) | \ + PIN_ODR_HIGH(GPIOG_PIN4) | \ + PIN_ODR_HIGH(GPIOG_PIN5) | \ + PIN_ODR_HIGH(GPIOG_PIN6) | \ + PIN_ODR_HIGH(GPIOG_PIN7) | \ + PIN_ODR_HIGH(GPIOG_PIN8) | \ + PIN_ODR_HIGH(GPIOG_PIN9) | \ + PIN_ODR_HIGH(GPIOG_PIN10) | \ + PIN_ODR_HIGH(GPIOG_PIN11) | \ + PIN_ODR_HIGH(GPIOG_PIN12) | \ + PIN_ODR_HIGH(GPIOG_PIN13) | \ + PIN_ODR_HIGH(GPIOG_PIN14) | \ + PIN_ODR_HIGH(GPIOG_PIN15)) +#define VAL_GPIOG_AFRL (PIN_AFIO_AF(GPIOG_PIN0, 0) | \ + PIN_AFIO_AF(GPIOG_PIN1, 0) | \ + PIN_AFIO_AF(GPIOG_PIN2, 0) | \ + PIN_AFIO_AF(GPIOG_PIN3, 0) | \ + PIN_AFIO_AF(GPIOG_PIN4, 0) | \ + PIN_AFIO_AF(GPIOG_PIN5, 0) | \ + PIN_AFIO_AF(GPIOG_PIN6, 0) | \ + PIN_AFIO_AF(GPIOG_PIN7, 0)) +#define VAL_GPIOG_AFRH (PIN_AFIO_AF(GPIOG_PIN8, 0) | \ + PIN_AFIO_AF(GPIOG_PIN9, 0) | \ + PIN_AFIO_AF(GPIOG_PIN10, 0) | \ + PIN_AFIO_AF(GPIOG_PIN11, 0) | \ + PIN_AFIO_AF(GPIOG_PIN12, 0) | \ + PIN_AFIO_AF(GPIOG_PIN13, 0) | \ + PIN_AFIO_AF(GPIOG_PIN14, 0) | \ + PIN_AFIO_AF(GPIOG_PIN15, 0)) + +/* + * GPIOH setup: + * + * PH0 - PIN0 (input pullup). + * PH1 - PIN1 (input pullup). + * PH2 - PIN2 (input pullup). + * PH3 - PIN3 (input pullup). + * PH4 - PIN4 (input pullup). + * PH5 - PIN5 (input pullup). + * PH6 - PIN6 (input pullup). + * PH7 - PIN7 (input pullup). + * PH8 - PIN8 (input pullup). + * PH9 - PIN9 (input pullup). + * PH10 - PIN10 (input pullup). + * PH11 - PIN11 (input pullup). + * PH12 - PIN12 (input pullup). + * PH13 - PIN13 (input pullup). + * PH14 - PIN14 (input pullup). + * PH15 - PIN15 (input pullup). + */ +#define VAL_GPIOH_MODER (PIN_MODE_INPUT(GPIOH_PIN0) | \ + PIN_MODE_INPUT(GPIOH_PIN1) | \ + PIN_MODE_INPUT(GPIOH_PIN2) | \ + PIN_MODE_INPUT(GPIOH_PIN3) | \ + PIN_MODE_INPUT(GPIOH_PIN4) | \ + PIN_MODE_INPUT(GPIOH_PIN5) | \ + PIN_MODE_INPUT(GPIOH_PIN6) | \ + PIN_MODE_INPUT(GPIOH_PIN7) | \ + PIN_MODE_INPUT(GPIOH_PIN8) | \ + PIN_MODE_INPUT(GPIOH_PIN9) | \ + PIN_MODE_INPUT(GPIOH_PIN10) | \ + PIN_MODE_INPUT(GPIOH_PIN11) | \ + PIN_MODE_INPUT(GPIOH_PIN12) | \ + PIN_MODE_INPUT(GPIOH_PIN13) | \ + PIN_MODE_INPUT(GPIOH_PIN14) | \ + PIN_MODE_INPUT(GPIOH_PIN15)) +#define VAL_GPIOH_OTYPER (PIN_OTYPE_PUSHPULL(GPIOH_PIN0) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN1) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN2) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN3) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN4) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN5) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN6) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN7) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN8) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN9) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN10) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN11) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN12) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN13) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN14) | \ + PIN_OTYPE_PUSHPULL(GPIOH_PIN15)) +#define VAL_GPIOH_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOH_PIN0) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN1) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN2) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN3) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN4) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN5) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN6) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN7) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN8) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN9) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN10) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN11) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN12) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN13) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN14) | \ + PIN_OSPEED_VERYLOW(GPIOH_PIN15)) +#define VAL_GPIOH_PUPDR (PIN_PUPDR_PULLUP(GPIOH_PIN0) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN1) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN2) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN3) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN4) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN5) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN6) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN7) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN8) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN9) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN10) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN11) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN12) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN13) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN14) | \ + PIN_PUPDR_PULLUP(GPIOH_PIN15)) +#define VAL_GPIOH_ODR (PIN_ODR_HIGH(GPIOH_PIN0) | \ + PIN_ODR_HIGH(GPIOH_PIN1) | \ + PIN_ODR_HIGH(GPIOH_PIN2) | \ + PIN_ODR_HIGH(GPIOH_PIN3) | \ + PIN_ODR_HIGH(GPIOH_PIN4) | \ + PIN_ODR_HIGH(GPIOH_PIN5) | \ + PIN_ODR_HIGH(GPIOH_PIN6) | \ + PIN_ODR_HIGH(GPIOH_PIN7) | \ + PIN_ODR_HIGH(GPIOH_PIN8) | \ + PIN_ODR_HIGH(GPIOH_PIN9) | \ + PIN_ODR_HIGH(GPIOH_PIN10) | \ + PIN_ODR_HIGH(GPIOH_PIN11) | \ + PIN_ODR_HIGH(GPIOH_PIN12) | \ + PIN_ODR_HIGH(GPIOH_PIN13) | \ + PIN_ODR_HIGH(GPIOH_PIN14) | \ + PIN_ODR_HIGH(GPIOH_PIN15)) +#define VAL_GPIOH_AFRL (PIN_AFIO_AF(GPIOH_PIN0, 0) | \ + PIN_AFIO_AF(GPIOH_PIN1, 0) | \ + PIN_AFIO_AF(GPIOH_PIN2, 0) | \ + PIN_AFIO_AF(GPIOH_PIN3, 0) | \ + PIN_AFIO_AF(GPIOH_PIN4, 0) | \ + PIN_AFIO_AF(GPIOH_PIN5, 0) | \ + PIN_AFIO_AF(GPIOH_PIN6, 0) | \ + PIN_AFIO_AF(GPIOH_PIN7, 0)) +#define VAL_GPIOH_AFRH (PIN_AFIO_AF(GPIOH_PIN8, 0) | \ + PIN_AFIO_AF(GPIOH_PIN9, 0) | \ + PIN_AFIO_AF(GPIOH_PIN10, 0) | \ + PIN_AFIO_AF(GPIOH_PIN11, 0) | \ + PIN_AFIO_AF(GPIOH_PIN12, 0) | \ + PIN_AFIO_AF(GPIOH_PIN13, 0) | \ + PIN_AFIO_AF(GPIOH_PIN14, 0) | \ + PIN_AFIO_AF(GPIOH_PIN15, 0)) + + +/* + * USB bus activation macro, required by the USB driver. + */ +// #define usb_lld_connect_bus(usbp) +#define usb_lld_connect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_ALTERNATE(14))) +// #define usb_lld_connect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_INPUT) +/* + * USB bus de-activation macro, required by the USB driver. + */ +// #define usb_lld_disconnect_bus(usbp) +#define usb_lld_disconnect_bus(usbp) (palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_OUTPUT_PUSHPULL)); palClearPad(GPIOA, GPIOA_USB_DP) +// #define usb_lld_disconnect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 12) + +#if !defined(_FROM_ASM_) +#ifdef __cplusplus +extern "C" { +#endif + void boardInit(void); +#ifdef __cplusplus +} +#endif +#endif /* _FROM_ASM_ */ + +#endif /* _BOARD_H_ */ diff --git a/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.mk b/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.mk new file mode 100644 index 0000000000..43377629a3 --- /dev/null +++ b/keyboards/planck/light/rev2/boards/GENERIC_STM32_F303XC/board.mk @@ -0,0 +1,5 @@ +# List of all the board related files. +BOARDSRC = $(BOARD_PATH)/boards/GENERIC_STM32_F303XC/board.c + +# Required include directories +BOARDINC = $(BOARD_PATH)/boards/GENERIC_STM32_F303XC diff --git a/keyboards/planck/light/rev2/bootloader_defs.h b/keyboards/planck/light/rev2/bootloader_defs.h new file mode 100644 index 0000000000..3b0e9d20a6 --- /dev/null +++ b/keyboards/planck/light/rev2/bootloader_defs.h @@ -0,0 +1,7 @@ +/* Address for jumping to bootloader on STM32 chips. */ +/* It is chip dependent, the correct number can be looked up here: + * http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf + * This also requires a patch to chibios: + * /tmk_core/tool/chibios/ch-bootloader-jump.patch + */ +#define STM32_BOOTLOADER_ADDRESS 0x1FFFD800 diff --git a/keyboards/planck/light/rev2/chconf.h b/keyboards/planck/light/rev2/chconf.h new file mode 100644 index 0000000000..b52ca7d2c8 --- /dev/null +++ b/keyboards/planck/light/rev2/chconf.h @@ -0,0 +1,520 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/chconf.h + * @brief Configuration file template. + * @details A copy of this file must be placed in each project directory, it + * contains the application specific kernel settings. + * + * @addtogroup config + * @details Kernel related settings and hooks. + * @{ + */ + +#ifndef CHCONF_H +#define CHCONF_H + +#define _CHIBIOS_RT_CONF_ + +/*===========================================================================*/ +/** + * @name System timers settings + * @{ + */ +/*===========================================================================*/ + +/** + * @brief System time counter resolution. + * @note Allowed values are 16 or 32 bits. + */ +#define CH_CFG_ST_RESOLUTION 16 + +/** + * @brief System tick frequency. + * @details Frequency of the system timer that drives the system ticks. This + * setting also defines the system tick time unit. + */ +#define CH_CFG_ST_FREQUENCY 10000 + +/** + * @brief Time delta constant for the tick-less mode. + * @note If this value is zero then the system uses the classic + * periodic tick. This value represents the minimum number + * of ticks that is safe to specify in a timeout directive. + * The value one is not valid, timeouts are rounded up to + * this value. + */ +#define CH_CFG_ST_TIMEDELTA 2 + +/** @} */ + +/*===========================================================================*/ +/** + * @name Kernel parameters and options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Round robin interval. + * @details This constant is the number of system ticks allowed for the + * threads before preemption occurs. Setting this value to zero + * disables the preemption for threads with equal priority and the + * round robin becomes cooperative. Note that higher priority + * threads can still preempt, the kernel is always preemptive. + * @note Disabling the round robin preemption makes the kernel more compact + * and generally faster. + * @note The round robin preemption is not supported in tickless mode and + * must be set to zero in that case. + */ +#define CH_CFG_TIME_QUANTUM 0 + +/** + * @brief Managed RAM size. + * @details Size of the RAM area to be managed by the OS. If set to zero + * then the whole available RAM is used. The core memory is made + * available to the heap allocator and/or can be used directly through + * the simplified core memory allocator. + * + * @note In order to let the OS manage the whole RAM the linker script must + * provide the @p __heap_base__ and @p __heap_end__ symbols. + * @note Requires @p CH_CFG_USE_MEMCORE. + */ +#define CH_CFG_MEMCORE_SIZE 0 + +/** + * @brief Idle thread automatic spawn suppression. + * @details When this option is activated the function @p chSysInit() + * does not spawn the idle thread. The application @p main() + * function becomes the idle thread and must implement an + * infinite loop. + */ +#define CH_CFG_NO_IDLE_THREAD FALSE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Performance options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief OS optimization. + * @details If enabled then time efficient rather than space efficient code + * is used when two possible implementations exist. + * + * @note This is not related to the compiler optimization options. + * @note The default is @p TRUE. + */ +#define CH_CFG_OPTIMIZE_SPEED TRUE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Subsystem options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Time Measurement APIs. + * @details If enabled then the time measurement APIs are included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_TM TRUE + +/** + * @brief Threads registry APIs. + * @details If enabled then the registry APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_REGISTRY TRUE + +/** + * @brief Threads synchronization APIs. + * @details If enabled then the @p chThdWait() function is included in + * the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_WAITEXIT TRUE + +/** + * @brief Semaphores APIs. + * @details If enabled then the Semaphores APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_SEMAPHORES TRUE + +/** + * @brief Semaphores queuing mode. + * @details If enabled then the threads are enqueued on semaphores by + * priority rather than in FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special + * requirements. + * @note Requires @p CH_CFG_USE_SEMAPHORES. + */ +#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE + +/** + * @brief Mutexes APIs. + * @details If enabled then the mutexes APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MUTEXES TRUE + +/** + * @brief Enables recursive behavior on mutexes. + * @note Recursive mutexes are heavier and have an increased + * memory footprint. + * + * @note The default is @p FALSE. + * @note Requires @p CH_CFG_USE_MUTEXES. + */ +#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE + +/** + * @brief Conditional Variables APIs. + * @details If enabled then the conditional variables APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_MUTEXES. + */ +#define CH_CFG_USE_CONDVARS TRUE + +/** + * @brief Conditional Variables APIs with timeout. + * @details If enabled then the conditional variables APIs with timeout + * specification are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_CONDVARS. + */ +#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE + +/** + * @brief Events Flags APIs. + * @details If enabled then the event flags APIs are included in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_EVENTS TRUE + +/** + * @brief Events Flags APIs with timeout. + * @details If enabled then the events APIs with timeout specification + * are included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_EVENTS. + */ +#define CH_CFG_USE_EVENTS_TIMEOUT TRUE + +/** + * @brief Synchronous Messages APIs. + * @details If enabled then the synchronous messages APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MESSAGES TRUE + +/** + * @brief Synchronous Messages queuing mode. + * @details If enabled then messages are served by priority rather than in + * FIFO order. + * + * @note The default is @p FALSE. Enable this if you have special + * requirements. + * @note Requires @p CH_CFG_USE_MESSAGES. + */ +#define CH_CFG_USE_MESSAGES_PRIORITY TRUE + +/** + * @brief Mailboxes APIs. + * @details If enabled then the asynchronous messages (mailboxes) APIs are + * included in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_SEMAPHORES. + */ +#define CH_CFG_USE_MAILBOXES TRUE + +/** + * @brief Core Memory Manager APIs. + * @details If enabled then the core memory manager APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MEMCORE TRUE + +/** + * @brief Heap Allocator APIs. + * @details If enabled then the memory heap allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or + * @p CH_CFG_USE_SEMAPHORES. + * @note Mutexes are recommended. + */ +#define CH_CFG_USE_HEAP TRUE + +/** + * @brief Memory Pools Allocator APIs. + * @details If enabled then the memory pools allocator APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + */ +#define CH_CFG_USE_MEMPOOLS TRUE + +/** + * @brief Dynamic Threads APIs. + * @details If enabled then the dynamic threads creation APIs are included + * in the kernel. + * + * @note The default is @p TRUE. + * @note Requires @p CH_CFG_USE_WAITEXIT. + * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS. + */ +#define CH_CFG_USE_DYNAMIC TRUE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Debug options + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Debug option, kernel statistics. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_STATISTICS FALSE + +/** + * @brief Debug option, system state check. + * @details If enabled the correct call protocol for system APIs is checked + * at runtime. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_SYSTEM_STATE_CHECK FALSE + +/** + * @brief Debug option, parameters checks. + * @details If enabled then the checks on the API functions input + * parameters are activated. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_ENABLE_CHECKS FALSE + +/** + * @brief Debug option, consistency checks. + * @details If enabled then all the assertions in the kernel code are + * activated. This includes consistency checks inside the kernel, + * runtime anomalies and port-defined checks. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_ENABLE_ASSERTS FALSE + +/** + * @brief Debug option, trace buffer. + * @details If enabled then the trace buffer is activated. + * + * @note The default is @p CH_DBG_TRACE_MASK_DISABLED. + */ +#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED + +/** + * @brief Trace buffer entries. + * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is + * different from @p CH_DBG_TRACE_MASK_DISABLED. + */ +#define CH_DBG_TRACE_BUFFER_SIZE 128 + +/** + * @brief Debug option, stack checks. + * @details If enabled then a runtime stack check is performed. + * + * @note The default is @p FALSE. + * @note The stack check is performed in a architecture/port dependent way. + * It may not be implemented or some ports. + * @note The default failure mode is to halt the system with the global + * @p panic_msg variable set to @p NULL. + */ +#define CH_DBG_ENABLE_STACK_CHECK TRUE + +/** + * @brief Debug option, stacks initialization. + * @details If enabled then the threads working area is filled with a byte + * value when a thread is created. This can be useful for the + * runtime measurement of the used stack. + * + * @note The default is @p FALSE. + */ +#define CH_DBG_FILL_THREADS FALSE + +/** + * @brief Debug option, threads profiling. + * @details If enabled then a field is added to the @p thread_t structure that + * counts the system ticks occurred while executing the thread. + * + * @note The default is @p FALSE. + * @note This debug option is not currently compatible with the + * tickless mode. + */ +#define CH_DBG_THREADS_PROFILING FALSE + +/** @} */ + +/*===========================================================================*/ +/** + * @name Kernel hooks + * @{ + */ +/*===========================================================================*/ + +/** + * @brief Threads descriptor structure extension. + * @details User fields added to the end of the @p thread_t structure. + */ +#define CH_CFG_THREAD_EXTRA_FIELDS \ + /* Add threads custom fields here.*/ + +/** + * @brief Threads initialization hook. + * @details User initialization code added to the @p chThdInit() API. + * + * @note It is invoked from within @p chThdInit() and implicitly from all + * the threads creation APIs. + */ +#define CH_CFG_THREAD_INIT_HOOK(tp) { \ + /* Add threads initialization code here.*/ \ +} + +/** + * @brief Threads finalization hook. + * @details User finalization code added to the @p chThdExit() API. + */ +#define CH_CFG_THREAD_EXIT_HOOK(tp) { \ + /* Add threads finalization code here.*/ \ +} + +/** + * @brief Context switch hook. + * @details This hook is invoked just before switching between threads. + */ +#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \ + /* Context switch code here.*/ \ +} + +/** + * @brief ISR enter hook. + */ +#define CH_CFG_IRQ_PROLOGUE_HOOK() { \ + /* IRQ prologue code here.*/ \ +} + +/** + * @brief ISR exit hook. + */ +#define CH_CFG_IRQ_EPILOGUE_HOOK() { \ + /* IRQ epilogue code here.*/ \ +} + +/** + * @brief Idle thread enter hook. + * @note This hook is invoked within a critical zone, no OS functions + * should be invoked from here. + * @note This macro can be used to activate a power saving mode. + */ +#define CH_CFG_IDLE_ENTER_HOOK() { \ + /* Idle-enter code here.*/ \ +} + +/** + * @brief Idle thread leave hook. + * @note This hook is invoked within a critical zone, no OS functions + * should be invoked from here. + * @note This macro can be used to deactivate a power saving mode. + */ +#define CH_CFG_IDLE_LEAVE_HOOK() { \ + /* Idle-leave code here.*/ \ +} + +/** + * @brief Idle Loop hook. + * @details This hook is continuously invoked by the idle thread loop. + */ +#define CH_CFG_IDLE_LOOP_HOOK() { \ + /* Idle loop code here.*/ \ +} + +/** + * @brief System tick event hook. + * @details This hook is invoked in the system tick handler immediately + * after processing the virtual timers queue. + */ +#define CH_CFG_SYSTEM_TICK_HOOK() { \ + /* System tick event code here.*/ \ +} + +/** + * @brief System halt hook. + * @details This hook is invoked in case to a system halting error before + * the system is halted. + */ +#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ + /* System halt code here.*/ \ +} + +/** + * @brief Trace hook. + * @details This hook is invoked each time a new record is written in the + * trace buffer. + */ +#define CH_CFG_TRACE_HOOK(tep) { \ + /* Trace code here.*/ \ +} + +/** @} */ + +/*===========================================================================*/ +/* Port-specific settings (override port settings defaulted in chcore.h). */ +/*===========================================================================*/ + +#endif /* CHCONF_H */ + +/** @} */ diff --git a/keyboards/planck/light/rev2/config.h b/keyboards/planck/light/rev2/config.h new file mode 100644 index 0000000000..470aab1fae --- /dev/null +++ b/keyboards/planck/light/rev2/config.h @@ -0,0 +1,143 @@ +/* + * Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef REV6_CONFIG_H +#define REV6_CONFIG_H + +/* USB Device descriptor parameter */ +#define DEVICE_VER 0x0006 + +#undef MATRIX_ROWS +#undef MATRIX_COLS +/* key matrix size */ +#define MATRIX_ROWS 8 +#define MATRIX_COLS 6 + +/* + * Keyboard Matrix Assignments + * + * Change this to how you wired your keyboard + * COLS: AVR pins used for columns, left to right + * ROWS: AVR pins used for rows, top to bottom + * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode) + * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) + * +*/ +/* Note: These are not used for arm boards. They're here purely as documentation. + * #define MATRIX_ROW_PINS { PB0, PB1, PB2, PA15, PA10 } + * #define MATRIX_COL_PINS { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 } + * #define UNUSED_PINS + */ + +#define MUSIC_MAP +#undef AUDIO_VOICES +#undef C6_AUDIO + +/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ +#define DEBOUNCE 6 + +/* Prevent modifiers from being stuck on after layer changes. */ +#define PREVENT_STUCK_MODIFIERS + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +//#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +//#define LOCKING_RESYNC_ENABLE + +/* + * Force NKRO + * + * Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved + * state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the + * makefile for this to work.) + * + * If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N) + * until the next keyboard reset. + * + * NKRO may prevent your keystrokes from being detected in the BIOS, but it is + * fully operational during normal computer usage. + * + * For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N) + * or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by + * bootmagic, NKRO mode will always be enabled until it is toggled again during a + * power-up. + * + */ +//#define FORCE_NKRO + +/* key combination for magic key command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + +/* + * MIDI options + */ + +/* Prevent use of disabled MIDI features in the keymap */ +//#define MIDI_ENABLE_STRICT 1 + +/* enable basic MIDI features: + - MIDI notes can be sent when in Music mode is on +*/ +//#define MIDI_BASIC + +/* enable advanced MIDI features: + - MIDI notes can be added to the keymap + - Octave shift and transpose + - Virtual sustain, portamento, and modulation wheel + - etc. +*/ +//#define MIDI_ADVANCED + +/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ +//#define MIDI_TONE_KEYCODE_OCTAVES 1 + +// This is a 7-bit address, that gets left-shifted and bit 0 +// set to 0 for write, 1 for read (as per I2C protocol) +// The address will vary depending on your wiring: +// 0b1110100 AD <-> GND +// 0b1110111 AD <-> VCC +// 0b1110101 AD <-> SCL +// 0b1110110 AD <-> SDA +#define DRIVER_ADDR_1 0b1110100 +#define DRIVER_ADDR_2 0b1110110 + +#define DRIVER_COUNT 2 +#define DRIVER_1_LED_TOTAL 25 +#define DRIVER_2_LED_TOTAL 24 +#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL + +#endif diff --git a/keyboards/planck/light/rev2/halconf.h b/keyboards/planck/light/rev2/halconf.h new file mode 100644 index 0000000000..a14ace02b4 --- /dev/null +++ b/keyboards/planck/light/rev2/halconf.h @@ -0,0 +1,388 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/** + * @file templates/halconf.h + * @brief HAL configuration header. + * @details HAL configuration file, this file allows to enable or disable the + * various device drivers from your application. You may also use + * this file in order to override the device drivers default settings. + * + * @addtogroup HAL_CONF + * @{ + */ + +#ifndef HALCONF_H +#define HALCONF_H + +#include "mcuconf.h" + +/** + * @brief Enables the PAL subsystem. + */ +#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__) +#define HAL_USE_PAL TRUE +#endif + +/** + * @brief Enables the ADC subsystem. + */ +#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) +#define HAL_USE_ADC FALSE +#endif + +/** + * @brief Enables the CAN subsystem. + */ +#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__) +#define HAL_USE_CAN FALSE +#endif + +/** + * @brief Enables the DAC subsystem. + */ +#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__) +#define HAL_USE_DAC TRUE +#endif + +/** + * @brief Enables the EXT subsystem. + */ +#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__) +#define HAL_USE_EXT FALSE +#endif + +/** + * @brief Enables the GPT subsystem. + */ +#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__) +#define HAL_USE_GPT TRUE +#endif + +/** + * @brief Enables the I2C subsystem. + */ +#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) +#define HAL_USE_I2C TRUE +#endif + +/** + * @brief Enables the I2S subsystem. + */ +#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__) +#define HAL_USE_I2S FALSE +#endif + +/** + * @brief Enables the ICU subsystem. + */ +#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__) +#define HAL_USE_ICU FALSE +#endif + +/** + * @brief Enables the MAC subsystem. + */ +#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__) +#define HAL_USE_MAC FALSE +#endif + +/** + * @brief Enables the MMC_SPI subsystem. + */ +#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__) +#define HAL_USE_MMC_SPI FALSE +#endif + +/** + * @brief Enables the PWM subsystem. + */ +#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) +#define HAL_USE_PWM TRUE +#endif + +/** + * @brief Enables the QSPI subsystem. + */ +#if !defined(HAL_USE_QSPI) || defined(__DOXYGEN__) +#define HAL_USE_QSPI FALSE +#endif + +/** + * @brief Enables the RTC subsystem. + */ +#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) +#define HAL_USE_RTC FALSE +#endif + +/** + * @brief Enables the SDC subsystem. + */ +#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__) +#define HAL_USE_SDC FALSE +#endif + +/** + * @brief Enables the SERIAL subsystem. + */ +#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL FALSE +#endif + +/** + * @brief Enables the SERIAL over USB subsystem. + */ +#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) +#define HAL_USE_SERIAL_USB TRUE +#endif + +/** + * @brief Enables the SPI subsystem. + */ +#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__) +#define HAL_USE_SPI FALSE +#endif + +/** + * @brief Enables the UART subsystem. + */ +#if !defined(HAL_USE_UART) || defined(__DOXYGEN__) +#define HAL_USE_UART FALSE +#endif + +/** + * @brief Enables the USB subsystem. + */ +#if !defined(HAL_USE_USB) || defined(__DOXYGEN__) +#define HAL_USE_USB TRUE +#endif + +/** + * @brief Enables the WDG subsystem. + */ +#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__) +#define HAL_USE_WDG FALSE +#endif + +/*===========================================================================*/ +/* ADC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__) +#define ADC_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define ADC_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* CAN driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Sleep mode related APIs inclusion switch. + */ +#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__) +#define CAN_USE_SLEEP_MODE TRUE +#endif + +/*===========================================================================*/ +/* I2C driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables the mutual exclusion APIs on the I2C bus. + */ +#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define I2C_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* MAC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__) +#define MAC_USE_ZERO_COPY FALSE +#endif + +/** + * @brief Enables an event sources for incoming packets. + */ +#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__) +#define MAC_USE_EVENTS TRUE +#endif + +/*===========================================================================*/ +/* MMC_SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + * This option is recommended also if the SPI driver does not + * use a DMA channel and heavily loads the CPU. + */ +#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__) +#define MMC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SDC driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Number of initialization attempts before rejecting the card. + * @note Attempts are performed at 10mS intervals. + */ +#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__) +#define SDC_INIT_RETRY 100 +#endif + +/** + * @brief Include support for MMC cards. + * @note MMC support is not yet implemented so this option must be kept + * at @p FALSE. + */ +#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__) +#define SDC_MMC_SUPPORT FALSE +#endif + +/** + * @brief Delays insertions. + * @details If enabled this options inserts delays into the MMC waiting + * routines releasing some extra CPU time for the threads with + * lower priority, this may slow down the driver a bit however. + */ +#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__) +#define SDC_NICE_WAITING TRUE +#endif + +/*===========================================================================*/ +/* SERIAL driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Default bit rate. + * @details Configuration parameter, this is the baud rate selected for the + * default configuration. + */ +#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__) +#define SERIAL_DEFAULT_BITRATE 38400 +#endif + +/** + * @brief Serial buffers size. + * @details Configuration parameter, you can change the depth of the queue + * buffers depending on the requirements of your application. + * @note The default is 16 bytes for both the transmission and receive + * buffers. + */ +#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define SERIAL_BUFFERS_SIZE 16 +#endif + +/*===========================================================================*/ +/* SERIAL_USB driver related setting. */ +/*===========================================================================*/ + +/** + * @brief Serial over USB buffers size. + * @details Configuration parameter, the buffer size must be a multiple of + * the USB data endpoint maximum packet size. + * @note The default is 256 bytes for both the transmission and receive + * buffers. + */ +#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__) +#define SERIAL_USB_BUFFERS_SIZE 1 +#endif + +/** + * @brief Serial over USB number of buffers. + * @note The default is 2 buffers. + */ +#if !defined(SERIAL_USB_BUFFERS_NUMBER) || defined(__DOXYGEN__) +#define SERIAL_USB_BUFFERS_NUMBER 2 +#endif + +/*===========================================================================*/ +/* SPI driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__) +#define SPI_USE_WAIT TRUE +#endif + +/** + * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define SPI_USE_MUTUAL_EXCLUSION TRUE +#endif + +/*===========================================================================*/ +/* UART driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__) +#define UART_USE_WAIT FALSE +#endif + +/** + * @brief Enables the @p uartAcquireBus() and @p uartReleaseBus() APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(UART_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__) +#define UART_USE_MUTUAL_EXCLUSION FALSE +#endif + +/*===========================================================================*/ +/* USB driver related settings. */ +/*===========================================================================*/ + +/** + * @brief Enables synchronous APIs. + * @note Disabling this option saves both code and data space. + */ +#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__) +#define USB_USE_WAIT TRUE +#endif + +#endif /* HALCONF_H */ + +/** @} */ diff --git a/keyboards/planck/light/rev2/matrix.c b/keyboards/planck/light/rev2/matrix.c new file mode 100644 index 0000000000..5b6b8ebe8a --- /dev/null +++ b/keyboards/planck/light/rev2/matrix.c @@ -0,0 +1,191 @@ +#include +#include +#include +#include "hal.h" +#include "timer.h" +#include "wait.h" +#include "printf.h" +#include "backlight.h" +#include "matrix.h" +#include "action.h" +#include "keycode.h" +#include + +/* + * col: { B11, B10, B2, B1, A7, B0 } + * row: { A10, A9, A8, B15, C13, C14, C15, A2 } + */ +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_COLS]; +static bool debouncing = false; +static uint16_t debouncing_time = 0; + +static uint8_t encoder_state = 0; +static int8_t encoder_value = 0; +static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; + +__attribute__ ((weak)) +void matrix_init_user(void) {} + +__attribute__ ((weak)) +void matrix_scan_user(void) {} + +__attribute__ ((weak)) +void matrix_init_kb(void) { + matrix_init_user(); +} + +__attribute__ ((weak)) +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +void matrix_init(void) { + printf("matrix init\n"); + //debug_matrix = true; + + // dip switch setup + palSetPadMode(GPIOB, 14, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOB, 9, PAL_MODE_INPUT_PULLUP); + + // encoder setup + palSetPadMode(GPIOB, 12, PAL_MODE_INPUT_PULLUP); + palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_PULLUP); + + encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); + + // actual matrix setup + palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL); + + palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOB, 15, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 13, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 14, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOC, 15, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_PULLDOWN); + + + memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t)); + memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t)); + + + matrix_init_quantum(); +} + +__attribute__ ((weak)) +void encoder_update(bool clockwise) { } + +#ifndef ENCODER_RESOLUTION + #define ENCODER_RESOLUTION 4 +#endif + +#define COUNTRECLOCKWISE 0 +#define CLOCKWISE 1 + +uint8_t matrix_scan(void) { + + // encoder on B12 and B13 + encoder_state <<= 2; + encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); + encoder_value += encoder_LUT[encoder_state & 0xF]; + if (encoder_value >= ENCODER_RESOLUTION) { + encoder_update(COUNTRECLOCKWISE); + } + if (encoder_value <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + encoder_update(CLOCKWISE); + } + encoder_value %= ENCODER_RESOLUTION; + + // actual matrix + for (int col = 0; col < MATRIX_COLS; col++) { + matrix_row_t data = 0; + + // strobe col { B11, B10, B2, B1, A7, B0 } + switch (col) { + case 0: palSetPad(GPIOB, 11); break; + case 1: palSetPad(GPIOB, 10); break; + case 2: palSetPad(GPIOB, 2); break; + case 3: palSetPad(GPIOB, 1); break; + case 4: palSetPad(GPIOA, 7); break; + case 5: palSetPad(GPIOB, 0); break; + } + + // need wait to settle pin state + wait_us(20); + + // read row data { A10, A9, A8, B15, C13, C14, C15, A2 } + data = ( + (palReadPad(GPIOA, 10) << 0 ) | + (palReadPad(GPIOA, 9) << 1 ) | + (palReadPad(GPIOA, 8) << 2 ) | + (palReadPad(GPIOB, 15) << 3 ) | + (palReadPad(GPIOC, 13) << 4 ) | + (palReadPad(GPIOC, 14) << 5 ) | + (palReadPad(GPIOC, 15) << 6 ) | + (palReadPad(GPIOA, 2) << 7 ) + ); + + // unstrobe col { B11, B10, B2, B1, A7, B0 } + switch (col) { + case 0: palClearPad(GPIOB, 11); break; + case 1: palClearPad(GPIOB, 10); break; + case 2: palClearPad(GPIOB, 2); break; + case 3: palClearPad(GPIOB, 1); break; + case 4: palClearPad(GPIOA, 7); break; + case 5: palClearPad(GPIOB, 0); break; + } + + if (matrix_debouncing[col] != data) { + matrix_debouncing[col] = data; + debouncing = true; + debouncing_time = timer_read(); + } + } + + if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { + for (int row = 0; row < MATRIX_ROWS; row++) { + matrix[row] = 0; + for (int col = 0; col < MATRIX_COLS; col++) { + matrix[row] |= ((matrix_debouncing[col] & (1 << row) ? 1 : 0) << col); + } + } + debouncing = false; + } + + matrix_scan_quantum(); + + return 1; +} + +bool matrix_is_on(uint8_t row, uint8_t col) { + return (matrix[row] & (1< + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "rev2.h" + +void matrix_init_kb(void) { + matrix_init_user(); +} + +void matrix_scan_kb(void) { + matrix_scan_user(); +} diff --git a/keyboards/planck/light/rev2/rev2.h b/keyboards/planck/light/rev2/rev2.h new file mode 100644 index 0000000000..d9354d9755 --- /dev/null +++ b/keyboards/planck/light/rev2/rev2.h @@ -0,0 +1,21 @@ +/* Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef REV2_H +#define REV2_H + +#include QMK_KEYBOARD_H + +#endif diff --git a/keyboards/planck/light/rev2/rules.mk b/keyboards/planck/light/rev2/rules.mk new file mode 100644 index 0000000000..f037375bc1 --- /dev/null +++ b/keyboards/planck/light/rev2/rules.mk @@ -0,0 +1,56 @@ +# project specific files +SRC = matrix.c +LAYOUTS += ortho_4x12 + +## chip/board settings +# - the next two should match the directories in +# /os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) +MCU_FAMILY = STM32 +MCU_SERIES = STM32F3xx + +# Linker script to use +# - it should exist either in /os/common/ports/ARMCMx/compilers/GCC/ld/ +# or /ld/ +MCU_LDSCRIPT = STM32F303xC + +# Startup code to use +# - it should exist in /os/common/startup/ARMCMx/compilers/GCC/mk/ +MCU_STARTUP = stm32f3xx + +# Board: it should exist either in /os/hal/boards/ +# or /boards +BOARD = GENERIC_STM32_F303XC + +# Cortex version +MCU = cortex-m4 + +# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7 +ARMV = 7 + +USE_FPU = yes + +# Vector table for application +# 0x00000000-0x00001000 area is occupied by bootlaoder.*/ +# The CORTEX_VTOR... is needed only for MCHCK/Infinity KB +# OPT_DEFS = -DCORTEX_VTOR_INIT=0x08005000 +OPT_DEFS = + +# Options to pass to dfu-util when flashing +DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000:leave + +# Build Options +# comment out to disable the options. +# +BACKLIGHT_ENABLE = no +BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration +## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.) +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = yes # Commands for debug and configuration +#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +NKRO_ENABLE = yes # USB Nkey Rollover +CUSTOM_MATRIX = yes # Custom matrix file +AUDIO_ENABLE = yes +RGB_MATRIX_ENABLE = yes +# SERIAL_LINK_ENABLE = yes diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index e4ebe48acc..2c5f906ac5 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -96,6 +96,9 @@ bool last_dip_switch[4] = {0}; #define ENCODER_RESOLUTION 4 #endif +#define COUNTRECLOCKWISE 0 +#define CLOCKWISE 1 + uint8_t matrix_scan(void) { // dip switch dip_switch[0] = !palReadPad(GPIOB, 14); @@ -113,10 +116,10 @@ uint8_t matrix_scan(void) { encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); encoder_value += encoder_LUT[encoder_state & 0xF]; if (encoder_value >= ENCODER_RESOLUTION) { - encoder_update(0); + encoder_update(COUNTRECLOCKWISE); } if (encoder_value <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise - encoder_update(1); + encoder_update(CLOCKWISE); } encoder_value %= ENCODER_RESOLUTION; From 274283420df035618cc2cb51118015778ac97944 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 1 Jun 2018 14:33:13 -0400 Subject: [PATCH 37/42] rev2 working --- drivers/arm/is31fl3731.c | 6 +- drivers/arm/twi2c.c | 24 ++++---- keyboards/planck/light/rev2/chconf.h | 2 +- keyboards/planck/light/rev2/config.h | 10 ++- keyboards/planck/light/rev2/halconf.h | 2 +- keyboards/planck/light/rev2/matrix.c | 88 ++++++++++++++------------- keyboards/planck/light/rev2/mcuconf.h | 6 +- keyboards/planck/light/rev2/rev2.c | 8 --- keyboards/planck/planck.h | 2 +- quantum/quantum.h | 7 ++- quantum/rgb_matrix.c | 16 ++--- 11 files changed, 88 insertions(+), 83 deletions(-) diff --git a/drivers/arm/is31fl3731.c b/drivers/arm/is31fl3731.c index 4cf0c09f67..a6e02db1b3 100644 --- a/drivers/arm/is31fl3731.c +++ b/drivers/arm/is31fl3731.c @@ -82,7 +82,8 @@ void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data ) g_twi_transfer_buffer[1] = data; //Transmit data until succesful - while(twi2c_transmit(addr << 1, g_twi_transfer_buffer,2) != 0); + //while(twi2c_transmit(addr << 1, g_twi_transfer_buffer,2) != 0); + twi2c_transmit(addr << 1, g_twi_transfer_buffer,2); } void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ) @@ -106,7 +107,8 @@ void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ) } //Transmit buffer until succesful - while(twi2c_transmit(addr << 1, g_twi_transfer_buffer,17) != 0); + //while(twi2c_transmit(addr << 1, g_twi_transfer_buffer,17) != 0); + twi2c_transmit(addr << 1, g_twi_transfer_buffer,17); } } diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 9a08213833..53af437bc2 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -46,13 +46,12 @@ I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend; static uint8_t twi2c_address; -static const I2CConfig I2CConfig = { +static const I2CConfig i2cconfig = { STM32_TIMINGR_PRESC(15U) | STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) | STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U), 0, - 0, - NULL + 0 }; char initialReplyBody[50] = "Initial reply"; // 'Status' response if read without preceding write @@ -182,7 +181,7 @@ void twi2c_slave_init(void) { twi2c_init(); - i2cStart(&I2C_DRIVER, &I2CConfig); + i2cStart(&I2C_DRIVER, &i2cconfig); #if HAL_USE_I2C_SLAVE I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message #endif @@ -213,15 +212,16 @@ void twi2c_slave_task(void) { uint8_t twi2c_start(uint8_t address) { twi2c_address = address; - i2cStart(&I2C_DRIVER, &I2CConfig); + i2cStart(&I2C_DRIVER, &i2cconfig); + return 0; } void twi2c_init(void) { - palSetGroupMode(GPIOB,8,9, PAL_MODE_INPUT); // Try releasing special pins for a short time + palSetGroupMode(GPIOB,6,7, PAL_MODE_INPUT); // Try releasing special pins for a short time chThdSleepMilliseconds(10); - palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); - palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); + palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP); // try high drive (from kiibohd) // I2C_DRIVER.i2c->C2 |= I2Cx_C2_HDRS; @@ -229,14 +229,12 @@ void twi2c_init(void) { // I2C_DRIVER.i2c->FLT = 4; } -uint8_t buffer[1] = {0}; - uint8_t twi2c_write(uint8_t data) { - return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, &data, 1, buffer, 1, MS2ST(100)); + return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, &data, 1, 0, 0, MS2ST(100)); } uint8_t twi2c_transmit(uint8_t address, uint8_t* data, uint16_t length) { twi2c_address = address; - i2cStart(&I2C_DRIVER, &I2CConfig); - return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, data, length, buffer, 1, MS2ST(100)); + i2cStart(&I2C_DRIVER, &i2cconfig); + return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, data, length, 0, 0, MS2ST(100)); } diff --git a/keyboards/planck/light/rev2/chconf.h b/keyboards/planck/light/rev2/chconf.h index b52ca7d2c8..5a9b833107 100644 --- a/keyboards/planck/light/rev2/chconf.h +++ b/keyboards/planck/light/rev2/chconf.h @@ -41,7 +41,7 @@ * @brief System time counter resolution. * @note Allowed values are 16 or 32 bits. */ -#define CH_CFG_ST_RESOLUTION 16 +#define CH_CFG_ST_RESOLUTION 32 /** * @brief System tick frequency. diff --git a/keyboards/planck/light/rev2/config.h b/keyboards/planck/light/rev2/config.h index 470aab1fae..40cf3997d2 100644 --- a/keyboards/planck/light/rev2/config.h +++ b/keyboards/planck/light/rev2/config.h @@ -19,13 +19,17 @@ #define REV6_CONFIG_H /* USB Device descriptor parameter */ -#define DEVICE_VER 0x0006 +#undef PRODUCT +#define PRODUCT Planck Light +#undef PRODUCT_ID +#define PRODUCT_ID 0x6065 +#define DEVICE_VER 0x0002 #undef MATRIX_ROWS #undef MATRIX_COLS /* key matrix size */ -#define MATRIX_ROWS 8 -#define MATRIX_COLS 6 +#define MATRIX_ROWS 4 +#define MATRIX_COLS 12 /* * Keyboard Matrix Assignments diff --git a/keyboards/planck/light/rev2/halconf.h b/keyboards/planck/light/rev2/halconf.h index a14ace02b4..c3e0cbb728 100644 --- a/keyboards/planck/light/rev2/halconf.h +++ b/keyboards/planck/light/rev2/halconf.h @@ -111,7 +111,7 @@ * @brief Enables the PWM subsystem. */ #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) -#define HAL_USE_PWM TRUE +#define HAL_USE_PWM FALSE #endif /** diff --git a/keyboards/planck/light/rev2/matrix.c b/keyboards/planck/light/rev2/matrix.c index 5b6b8ebe8a..953c1c2b66 100644 --- a/keyboards/planck/light/rev2/matrix.c +++ b/keyboards/planck/light/rev2/matrix.c @@ -12,8 +12,8 @@ #include /* - * col: { B11, B10, B2, B1, A7, B0 } - * row: { A10, A9, A8, B15, C13, C14, C15, A2 } + * col: { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 } + * row: { B5, B10, A9, A8 } */ /* matrix state(1:on, 0:off) */ static matrix_row_t matrix[MATRIX_ROWS]; @@ -45,12 +45,6 @@ void matrix_init(void) { printf("matrix init\n"); //debug_matrix = true; - // dip switch setup - palSetPadMode(GPIOB, 14, PAL_MODE_INPUT_PULLUP); - palSetPadMode(GPIOA, 15, PAL_MODE_INPUT_PULLUP); - palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLUP); - palSetPadMode(GPIOB, 9, PAL_MODE_INPUT_PULLUP); - // encoder setup palSetPadMode(GPIOB, 12, PAL_MODE_INPUT_PULLUP); palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_PULLUP); @@ -58,21 +52,23 @@ void matrix_init(void) { encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); // actual matrix setup - palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 10, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 15, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 0, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 1, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL); + palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 10, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOB, 5, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOB, 10, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOB, 15, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOC, 13, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOC, 14, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOC, 15, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_PULLDOWN); + palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLDOWN); memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t)); @@ -110,39 +106,47 @@ uint8_t matrix_scan(void) { for (int col = 0; col < MATRIX_COLS; col++) { matrix_row_t data = 0; - // strobe col { B11, B10, B2, B1, A7, B0 } + // strobe col { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 } switch (col) { - case 0: palSetPad(GPIOB, 11); break; - case 1: palSetPad(GPIOB, 10); break; - case 2: palSetPad(GPIOB, 2); break; - case 3: palSetPad(GPIOB, 1); break; - case 4: palSetPad(GPIOA, 7); break; - case 5: palSetPad(GPIOB, 0); break; + case 0: palSetPad(GPIOA, 10); break; + case 1: palSetPad(GPIOB, 2); break; + case 2: palSetPad(GPIOA, 15); break; + case 3: palSetPad(GPIOA, 0); break; + case 4: palSetPad(GPIOA, 1); break; + case 5: palSetPad(GPIOA, 2); break; + case 6: palSetPad(GPIOB, 0); break; + case 7: palSetPad(GPIOB, 1); break; + case 8: palSetPad(GPIOC, 13); break; + case 9: palSetPad(GPIOA, 6); break; + case 10: palSetPad(GPIOA, 7); break; + case 11: palSetPad(GPIOA, 3); break; } // need wait to settle pin state wait_us(20); - // read row data { A10, A9, A8, B15, C13, C14, C15, A2 } + // read row data { B5, B10, A9, A8 } data = ( - (palReadPad(GPIOA, 10) << 0 ) | - (palReadPad(GPIOA, 9) << 1 ) | - (palReadPad(GPIOA, 8) << 2 ) | - (palReadPad(GPIOB, 15) << 3 ) | - (palReadPad(GPIOC, 13) << 4 ) | - (palReadPad(GPIOC, 14) << 5 ) | - (palReadPad(GPIOC, 15) << 6 ) | - (palReadPad(GPIOA, 2) << 7 ) + (palReadPad(GPIOB, 5) << 0 ) | + (palReadPad(GPIOB, 10) << 1 ) | + (palReadPad(GPIOA, 9) << 2 ) | + (palReadPad(GPIOA, 8) << 3 ) ); // unstrobe col { B11, B10, B2, B1, A7, B0 } switch (col) { - case 0: palClearPad(GPIOB, 11); break; - case 1: palClearPad(GPIOB, 10); break; - case 2: palClearPad(GPIOB, 2); break; - case 3: palClearPad(GPIOB, 1); break; - case 4: palClearPad(GPIOA, 7); break; - case 5: palClearPad(GPIOB, 0); break; + case 0: palClearPad(GPIOA, 10); break; + case 1: palClearPad(GPIOB, 2); break; + case 2: palClearPad(GPIOA, 15); break; + case 3: palClearPad(GPIOA, 0); break; + case 4: palClearPad(GPIOA, 1); break; + case 5: palClearPad(GPIOA, 2); break; + case 6: palClearPad(GPIOB, 0); break; + case 7: palClearPad(GPIOB, 1); break; + case 8: palClearPad(GPIOC, 13); break; + case 9: palClearPad(GPIOA, 6); break; + case 10: palClearPad(GPIOA, 7); break; + case 11: palClearPad(GPIOA, 3); break; } if (matrix_debouncing[col] != data) { diff --git a/keyboards/planck/light/rev2/mcuconf.h b/keyboards/planck/light/rev2/mcuconf.h index 867a7984d5..1ef0a0b9eb 100644 --- a/keyboards/planck/light/rev2/mcuconf.h +++ b/keyboards/planck/light/rev2/mcuconf.h @@ -183,8 +183,8 @@ */ #define STM32_PWM_USE_ADVANCED FALSE #define STM32_PWM_USE_TIM1 FALSE -#define STM32_PWM_USE_TIM2 TRUE -#define STM32_PWM_USE_TIM3 TRUE +#define STM32_PWM_USE_TIM2 FALSE +#define STM32_PWM_USE_TIM3 FALSE #define STM32_PWM_USE_TIM4 FALSE #define STM32_PWM_USE_TIM8 FALSE #define STM32_PWM_TIM1_IRQ_PRIORITY 7 @@ -225,7 +225,7 @@ * ST driver system settings. */ #define STM32_ST_IRQ_PRIORITY 8 -#define STM32_ST_USE_TIMER 4 +#define STM32_ST_USE_TIMER 2 /* * UART driver system settings. diff --git a/keyboards/planck/light/rev2/rev2.c b/keyboards/planck/light/rev2/rev2.c index f431f2fe6f..0754aabeb3 100644 --- a/keyboards/planck/light/rev2/rev2.c +++ b/keyboards/planck/light/rev2/rev2.c @@ -14,11 +14,3 @@ * along with this program. If not, see . */ #include "rev2.h" - -void matrix_init_kb(void) { - matrix_init_user(); -} - -void matrix_scan_kb(void) { - matrix_scan_user(); -} diff --git a/keyboards/planck/planck.h b/keyboards/planck/planck.h index f0a12d9335..b1b60ab89b 100644 --- a/keyboards/planck/planck.h +++ b/keyboards/planck/planck.h @@ -3,7 +3,7 @@ #include "quantum.h" -#ifdef __AVR__ +#if defined(__AVR__) || defined (KEYBOARD_planck_light_rev2) #define LAYOUT_planck_mit( \ k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0a, k0b, \ k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, \ diff --git a/quantum/quantum.h b/quantum/quantum.h index 2958a0abd0..36eeedd494 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -27,7 +27,7 @@ #ifdef BACKLIGHT_ENABLE #include "backlight.h" #endif -#if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE) +#if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE) #include "rgb.h" #endif #ifdef RGBLIGHT_ENABLE @@ -121,6 +121,11 @@ extern uint32_t default_layer_state; #include "process_terminal_nop.h" #endif +#ifndef MIN + #define MAX(x, y) (((x) > (y)) ? (x) : (y)) + #define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#endif + #define STRINGIZE(z) #z #define ADD_SLASH_X(y) STRINGIZE(\x ## y) #define SYMBOL_STR(x) ADD_SLASH_X(x) diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 992ce99de9..d29a65b907 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -17,14 +17,14 @@ #include "rgb_matrix.h" -#include -#include "i2c_master.h" -#include -#include +//#include +#include "twi2c.h" +#include "wait.h" +//#include #include "progmem.h" #include "config.h" #include "eeprom.h" -#include "lufa.h" +//#include "lufa.h" #include rgb_config_t rgb_matrix_config; @@ -217,7 +217,7 @@ void rgb_matrix_single_LED_test(void) { } // All LEDs off -void rgb_matrix_all_off(void) { +void rgb_matrix_all_off(void) { rgb_matrix_set_color_all( 0, 0, 0 ); } @@ -243,7 +243,7 @@ void rgb_matrix_solid_reactive(void) { // alphas = color1, mods = color2 void rgb_matrix_alphas_mods(void) { - + RGB rgb1 = hsv_to_rgb( (HSV){ .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); RGB rgb2 = hsv_to_rgb( (HSV){ .h = (rgb_matrix_config.hue + 180) % 360, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); @@ -723,7 +723,7 @@ void rgb_matrix_indicators_user(void) {} void rgb_matrix_init_drivers(void) { // Initialize TWI - i2c_init(); + twi2c_init(); IS31FL3731_init( DRIVER_ADDR_1 ); IS31FL3731_init( DRIVER_ADDR_2 ); From c1f6f1308bbc3c405e654a1d3ac1f068488fbd71 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 1 Jun 2018 16:37:15 -0400 Subject: [PATCH 38/42] move drivers around --- common_features.mk | 1 + drivers/avr/i2c_master.h | 22 --- drivers/avr/is31fl3731.c | 244 -------------------------- drivers/avr/is31fl3731.h | 214 ---------------------- drivers/avr/{i2c_master.c => twi2c.c} | 122 ++++++------- drivers/avr/twi2c.h | 22 +++ drivers/{arm => }/is31fl3731.c | 0 drivers/{arm => }/is31fl3731.h | 0 8 files changed, 84 insertions(+), 541 deletions(-) delete mode 100755 drivers/avr/i2c_master.h delete mode 100644 drivers/avr/is31fl3731.c delete mode 100644 drivers/avr/is31fl3731.h rename drivers/avr/{i2c_master.c => twi2c.c} (62%) mode change 100755 => 100644 create mode 100644 drivers/avr/twi2c.h rename drivers/{arm => }/is31fl3731.c (100%) rename drivers/{arm => }/is31fl3731.h (100%) diff --git a/common_features.mk b/common_features.mk index c1f8421c88..a4e744bdb7 100644 --- a/common_features.mk +++ b/common_features.mk @@ -20,6 +20,7 @@ SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) SERIAL_DEFS += -DSERIAL_LINK_ENABLE COMMON_VPATH += $(SERIAL_PATH) +COMMON_VPATH += $(DRIVER_PATH) ifeq ($(PLATFORM),AVR) COMMON_VPATH += $(DRIVER_PATH)/avr else diff --git a/drivers/avr/i2c_master.h b/drivers/avr/i2c_master.h deleted file mode 100755 index 2479d28d52..0000000000 --- a/drivers/avr/i2c_master.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Library made by: g4lvanix - * Github repository: https://github.com/g4lvanix/I2C-master-lib - */ - -#ifndef I2C_MASTER_H -#define I2C_MASTER_H - -#define I2C_READ 0x01 -#define I2C_WRITE 0x00 - -void i2c_init(void); -uint8_t i2c_start(uint8_t address); -uint8_t i2c_write(uint8_t data); -uint8_t i2c_read_ack(void); -uint8_t i2c_read_nack(void); -uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length); -uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length); -uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length); -uint8_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length); -void i2c_stop(void); - -#endif // I2C_MASTER_H diff --git a/drivers/avr/is31fl3731.c b/drivers/avr/is31fl3731.c deleted file mode 100644 index c7a99e3a3d..0000000000 --- a/drivers/avr/is31fl3731.c +++ /dev/null @@ -1,244 +0,0 @@ -/* Copyright 2017 Jason Williams - * Copyright 2018 Jack Humbert - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "is31fl3731.h" -#include -#include -#include -#include -#include "i2c_master.h" -#include "progmem.h" - -// This is a 7-bit address, that gets left-shifted and bit 0 -// set to 0 for write, 1 for read (as per I2C protocol) -// The address will vary depending on your wiring: -// 0b1110100 AD <-> GND -// 0b1110111 AD <-> VCC -// 0b1110101 AD <-> SCL -// 0b1110110 AD <-> SDA -#define ISSI_ADDR_DEFAULT 0x74 - -#define ISSI_REG_CONFIG 0x00 -#define ISSI_REG_CONFIG_PICTUREMODE 0x00 -#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08 -#define ISSI_REG_CONFIG_AUDIOPLAYMODE 0x18 - -#define ISSI_CONF_PICTUREMODE 0x00 -#define ISSI_CONF_AUTOFRAMEMODE 0x04 -#define ISSI_CONF_AUDIOMODE 0x08 - -#define ISSI_REG_PICTUREFRAME 0x01 - -#define ISSI_REG_SHUTDOWN 0x0A -#define ISSI_REG_AUDIOSYNC 0x06 - -#define ISSI_COMMANDREGISTER 0xFD -#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' - -// Transfer buffer for TWITransmitData() -uint8_t g_twi_transfer_buffer[20]; - -// These buffers match the IS31FL3731 PWM registers 0x24-0xB3. -// Storing them like this is optimal for I2C transfers to the registers. -// We could optimize this and take out the unused registers from these -// buffers and the transfers in IS31FL3731_write_pwm_buffer() but it's -// probably not worth the extra complexity. -uint8_t g_pwm_buffer[DRIVER_COUNT][144]; -bool g_pwm_buffer_update_required = false; - -uint8_t g_led_control_registers[DRIVER_COUNT][18] = { { 0 }, { 0 } }; -bool g_led_control_registers_update_required = false; - -// This is the bit pattern in the LED control registers -// (for matrix A, add one to register for matrix B) -// -// reg - b7 b6 b5 b4 b3 b2 b1 b0 -// 0x00 - R08,R07,R06,R05,R04,R03,R02,R01 -// 0x02 - G08,G07,G06,G05,G04,G03,G02,R00 -// 0x04 - B08,B07,B06,B05,B04,B03,G01,G00 -// 0x06 - - , - , - , - , - ,B02,B01,B00 -// 0x08 - - , - , - , - , - , - , - , - -// 0x0A - B17,B16,B15, - , - , - , - , - -// 0x0C - G17,G16,B14,B13,B12,B11,B10,B09 -// 0x0E - R17,G15,G14,G13,G12,G11,G10,G09 -// 0x10 - R16,R15,R14,R13,R12,R11,R10,R09 - - -void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data ) -{ - g_twi_transfer_buffer[0] = reg; - g_twi_transfer_buffer[1] = data; - - //Transmit data until succesful - while(i2c_transmit(addr << 1, g_twi_transfer_buffer,2) != 0); -} - -void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ) -{ - // assumes bank is already selected - - // transmit PWM registers in 9 transfers of 16 bytes - // g_twi_transfer_buffer[] is 20 bytes - - // iterate over the pwm_buffer contents at 16 byte intervals - for ( int i = 0; i < 144; i += 16 ) - { - // set the first register, e.g. 0x24, 0x34, 0x44, etc. - g_twi_transfer_buffer[0] = 0x24 + i; - // copy the data from i to i+15 - // device will auto-increment register for data after the first byte - // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer - for ( int j = 0; j < 16; j++ ) - { - g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; - } - - //Transmit buffer until succesful - while(i2c_transmit(addr << 1, g_twi_transfer_buffer,17) != 0); - } -} - -void IS31FL3731_init( uint8_t addr ) -{ - // In order to avoid the LEDs being driven with garbage data - // in the LED driver's PWM registers, first enable software shutdown, - // then set up the mode and other settings, clear the PWM registers, - // then disable software shutdown. - - // select "function register" bank - IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG ); - - // enable software shutdown - IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x00 ); - // this delay was copied from other drivers, might not be needed - _delay_ms( 10 ); - - // picture mode - IS31FL3731_write_register( addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE ); - // display frame 0 - IS31FL3731_write_register( addr, ISSI_REG_PICTUREFRAME, 0x00 ); - // audio sync off - IS31FL3731_write_register( addr, ISSI_REG_AUDIOSYNC, 0x00 ); - - // select bank 0 - IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 ); - - // turn off all LEDs in the LED control register - for ( int i = 0x00; i <= 0x11; i++ ) - { - IS31FL3731_write_register( addr, i, 0x00 ); - } - - // turn off all LEDs in the blink control register (not really needed) - for ( int i = 0x12; i <= 0x23; i++ ) - { - IS31FL3731_write_register( addr, i, 0x00 ); - } - - // set PWM on all LEDs to 0 - for ( int i = 0x24; i <= 0xB3; i++ ) - { - IS31FL3731_write_register( addr, i, 0x00 ); - } - - // select "function register" bank - IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG ); - - // disable software shutdown - IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x01 ); - - // select bank 0 and leave it selected. - // most usage after initialization is just writing PWM buffers in bank 0 - // as there's not much point in double-buffering - IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 ); -} - -void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) -{ - if ( index >= 0 && index < DRIVER_LED_TOTAL ) { - is31_led led = g_is31_leds[index]; - - // Subtract 0x24 to get the second index of g_pwm_buffer - g_pwm_buffer[led.driver][led.r - 0x24] = red; - g_pwm_buffer[led.driver][led.g - 0x24] = green; - g_pwm_buffer[led.driver][led.b - 0x24] = blue; - g_pwm_buffer_update_required = true; - } -} - -void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) -{ - for ( int i = 0; i < DRIVER_LED_TOTAL; i++ ) - { - IS31FL3731_set_color( i, red, green, blue ); - } -} - -void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue ) -{ - is31_led led = g_is31_leds[index]; - - uint8_t control_register_r = (led.r - 0x24) / 8; - uint8_t control_register_g = (led.g - 0x24) / 8; - uint8_t control_register_b = (led.b - 0x24) / 8; - uint8_t bit_r = (led.r - 0x24) % 8; - uint8_t bit_g = (led.g - 0x24) % 8; - uint8_t bit_b = (led.b - 0x24) % 8; - - if ( red ) { - g_led_control_registers[led.driver][control_register_r] |= (1 << bit_r); - } else { - g_led_control_registers[led.driver][control_register_r] &= ~(1 << bit_r); - } - if ( green ) { - g_led_control_registers[led.driver][control_register_g] |= (1 << bit_g); - } else { - g_led_control_registers[led.driver][control_register_g] &= ~(1 << bit_g); - } - if ( blue ) { - g_led_control_registers[led.driver][control_register_b] |= (1 << bit_b); - } else { - g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b); - } - - g_led_control_registers_update_required = true; - - -} - -void IS31FL3731_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ) -{ - if ( g_pwm_buffer_update_required ) - { - IS31FL3731_write_pwm_buffer( addr1, g_pwm_buffer[0] ); - IS31FL3731_write_pwm_buffer( addr2, g_pwm_buffer[1] ); - } - g_pwm_buffer_update_required = false; -} - -void IS31FL3731_update_led_control_registers( uint8_t addr1, uint8_t addr2 ) -{ - if ( g_led_control_registers_update_required ) - { - for ( int i=0; i<18; i++ ) - { - IS31FL3731_write_register(addr1, i, g_led_control_registers[0][i] ); - IS31FL3731_write_register(addr2, i, g_led_control_registers[1][i] ); - } - } -} - diff --git a/drivers/avr/is31fl3731.h b/drivers/avr/is31fl3731.h deleted file mode 100644 index 3d30fc67b7..0000000000 --- a/drivers/avr/is31fl3731.h +++ /dev/null @@ -1,214 +0,0 @@ -/* Copyright 2017 Jason Williams - * Copyright 2018 Jack Humbert - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#ifndef IS31FL3731_DRIVER_H -#define IS31FL3731_DRIVER_H - -#include -#include - -typedef struct is31_led { - uint8_t driver:2; - uint8_t r; - uint8_t g; - uint8_t b; -} __attribute__((packed)) is31_led; - -extern const is31_led g_is31_leds[DRIVER_LED_TOTAL]; - -void IS31FL3731_init( uint8_t addr ); -void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data ); -void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ); - -void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ); -void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue ); - -void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue ); - -// This should not be called from an interrupt -// (eg. from a timer interrupt). -// Call this while idle (in between matrix scans). -// If the buffer is dirty, it will update the driver with the buffer. -void IS31FL3731_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ); -void IS31FL3731_update_led_control_registers( uint8_t addr1, uint8_t addr2 ); - -#define C1_1 0x24 -#define C1_2 0x25 -#define C1_3 0x26 -#define C1_4 0x27 -#define C1_5 0x28 -#define C1_6 0x29 -#define C1_7 0x2A -#define C1_8 0x2B - -#define C1_9 0x2C -#define C1_10 0x2D -#define C1_11 0x2E -#define C1_12 0x2F -#define C1_13 0x30 -#define C1_14 0x31 -#define C1_15 0x32 -#define C1_16 0x33 - -#define C2_1 0x34 -#define C2_2 0x35 -#define C2_3 0x36 -#define C2_4 0x37 -#define C2_5 0x38 -#define C2_6 0x39 -#define C2_7 0x3A -#define C2_8 0x3B - -#define C2_9 0x3C -#define C2_10 0x3D -#define C2_11 0x3E -#define C2_12 0x3F -#define C2_13 0x40 -#define C2_14 0x41 -#define C2_15 0x42 -#define C2_16 0x43 - -#define C3_1 0x44 -#define C3_2 0x45 -#define C3_3 0x46 -#define C3_4 0x47 -#define C3_5 0x48 -#define C3_6 0x49 -#define C3_7 0x4A -#define C3_8 0x4B - -#define C3_9 0x4C -#define C3_10 0x4D -#define C3_11 0x4E -#define C3_12 0x4F -#define C3_13 0x50 -#define C3_14 0x51 -#define C3_15 0x52 -#define C3_16 0x53 - -#define C4_1 0x54 -#define C4_2 0x55 -#define C4_3 0x56 -#define C4_4 0x57 -#define C4_5 0x58 -#define C4_6 0x59 -#define C4_7 0x5A -#define C4_8 0x5B - -#define C4_9 0x5C -#define C4_10 0x5D -#define C4_11 0x5E -#define C4_12 0x5F -#define C4_13 0x60 -#define C4_14 0x61 -#define C4_15 0x62 -#define C4_16 0x63 - -#define C5_1 0x64 -#define C5_2 0x65 -#define C5_3 0x66 -#define C5_4 0x67 -#define C5_5 0x68 -#define C5_6 0x69 -#define C5_7 0x6A -#define C5_8 0x6B - -#define C5_9 0x6C -#define C5_10 0x6D -#define C5_11 0x6E -#define C5_12 0x6F -#define C5_13 0x70 -#define C5_14 0x71 -#define C5_15 0x72 -#define C5_16 0x73 - -#define C6_1 0x74 -#define C6_2 0x75 -#define C6_3 0x76 -#define C6_4 0x77 -#define C6_5 0x78 -#define C6_6 0x79 -#define C6_7 0x7A -#define C6_8 0x7B - -#define C6_9 0x7C -#define C6_10 0x7D -#define C6_11 0x7E -#define C6_12 0x7F -#define C6_13 0x80 -#define C6_14 0x81 -#define C6_15 0x82 -#define C6_16 0x83 - -#define C7_1 0x84 -#define C7_2 0x85 -#define C7_3 0x86 -#define C7_4 0x87 -#define C7_5 0x88 -#define C7_6 0x89 -#define C7_7 0x8A -#define C7_8 0x8B - -#define C7_9 0x8C -#define C7_10 0x8D -#define C7_11 0x8E -#define C7_12 0x8F -#define C7_13 0x90 -#define C7_14 0x91 -#define C7_15 0x92 -#define C7_16 0x93 - -#define C8_1 0x94 -#define C8_2 0x95 -#define C8_3 0x96 -#define C8_4 0x97 -#define C8_5 0x98 -#define C8_6 0x99 -#define C8_7 0x9A -#define C8_8 0x9B - -#define C8_9 0x9C -#define C8_10 0x9D -#define C8_11 0x9E -#define C8_12 0x9F -#define C8_13 0xA0 -#define C8_14 0xA1 -#define C8_15 0xA2 -#define C8_16 0xA3 - -#define C9_1 0xA4 -#define C9_2 0xA5 -#define C9_3 0xA6 -#define C9_4 0xA7 -#define C9_5 0xA8 -#define C9_6 0xA9 -#define C9_7 0xAA -#define C9_8 0xAB - -#define C9_9 0xAC -#define C9_10 0xAD -#define C9_11 0xAE -#define C9_12 0xAF -#define C9_13 0xB0 -#define C9_14 0xB1 -#define C9_15 0xB2 -#define C9_16 0xB3 - - - -#endif // IS31FL3731_DRIVER_H diff --git a/drivers/avr/i2c_master.c b/drivers/avr/twi2c.c old mode 100755 new mode 100644 similarity index 62% rename from drivers/avr/i2c_master.c rename to drivers/avr/twi2c.c index f4a4bb7b0b..c7df719d37 --- a/drivers/avr/i2c_master.c +++ b/drivers/avr/twi2c.c @@ -5,44 +5,44 @@ #include #include -#include "i2c_master.h" +#include "twi2c.h" #define F_SCL 400000UL // SCL frequency #define Prescaler 1 #define TWBR_val ((((F_CPU / F_SCL) / Prescaler) - 16 ) / 2) -void i2c_init(void) +void twi2c_init(void) { TWBR = (uint8_t)TWBR_val; } -uint8_t i2c_start(uint8_t address) +uint8_t twi2c_start(uint8_t address) { // reset TWI control register TWCR = 0; - // transmit START condition + // transmit START condition TWCR = (1< Date: Sun, 3 Jun 2018 18:01:11 -0400 Subject: [PATCH 39/42] arm lines implemented --- keyboards/planck/light/rev2/config.h | 11 +-- keyboards/planck/light/rev2/matrix.c | 69 ++++------------- quantum/config_common.h | 109 +++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 60 deletions(-) diff --git a/keyboards/planck/light/rev2/config.h b/keyboards/planck/light/rev2/config.h index 40cf3997d2..ebfb1ddea5 100644 --- a/keyboards/planck/light/rev2/config.h +++ b/keyboards/planck/light/rev2/config.h @@ -18,6 +18,8 @@ #ifndef REV6_CONFIG_H #define REV6_CONFIG_H +#include "config_common.h" + /* USB Device descriptor parameter */ #undef PRODUCT #define PRODUCT Planck Light @@ -41,11 +43,10 @@ * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) * */ -/* Note: These are not used for arm boards. They're here purely as documentation. - * #define MATRIX_ROW_PINS { PB0, PB1, PB2, PA15, PA10 } - * #define MATRIX_COL_PINS { PA2, PA3, PA6, PB14, PB15, PA8, PA9, PA7, PB3, PB4, PC14, PC15, PC13, PB5, PB6 } - * #define UNUSED_PINS - */ +#undef MATRIX_ROW_PINS +#undef MATRIX_COL_PINS +#define MATRIX_ROW_PINS { B5, B10, A9, A8 } +#define MATRIX_COL_PINS { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 } #define MUSIC_MAP #undef AUDIO_VOICES diff --git a/keyboards/planck/light/rev2/matrix.c b/keyboards/planck/light/rev2/matrix.c index 953c1c2b66..0a0f84ece3 100644 --- a/keyboards/planck/light/rev2/matrix.c +++ b/keyboards/planck/light/rev2/matrix.c @@ -25,6 +25,9 @@ static uint8_t encoder_state = 0; static int8_t encoder_value = 0; static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; +static LINE_TYPE matrix_col_pins[MATRIX_COLS] = MATRIX_COL_PINS; +static LINE_TYPE matrix_row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; + __attribute__ ((weak)) void matrix_init_user(void) {} @@ -52,29 +55,17 @@ void matrix_init(void) { encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); // actual matrix setup - palSetPadMode(GPIOA, 10, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 15, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 0, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 1, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 6, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 7, PAL_MODE_OUTPUT_PUSHPULL); - palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL); - - palSetPadMode(GPIOB, 5, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOB, 10, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOA, 9, PAL_MODE_INPUT_PULLDOWN); - palSetPadMode(GPIOA, 8, PAL_MODE_INPUT_PULLDOWN); + for (int i = 0; i < MATRIX_COLS; i++) { + setPadMode(matrix_col_pins[i], PAL_MODE_OUTPUT_PUSHPULL); + } + for (int i = 0; i < MATRIX_ROWS; i++) { + setPadMode(matrix_row_pins[i], PAL_MODE_INPUT_PULLDOWN); + } memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t)); memset(matrix_debouncing, 0, MATRIX_COLS * sizeof(matrix_row_t)); - matrix_init_quantum(); } @@ -106,49 +97,17 @@ uint8_t matrix_scan(void) { for (int col = 0; col < MATRIX_COLS; col++) { matrix_row_t data = 0; - // strobe col { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 } - switch (col) { - case 0: palSetPad(GPIOA, 10); break; - case 1: palSetPad(GPIOB, 2); break; - case 2: palSetPad(GPIOA, 15); break; - case 3: palSetPad(GPIOA, 0); break; - case 4: palSetPad(GPIOA, 1); break; - case 5: palSetPad(GPIOA, 2); break; - case 6: palSetPad(GPIOB, 0); break; - case 7: palSetPad(GPIOB, 1); break; - case 8: palSetPad(GPIOC, 13); break; - case 9: palSetPad(GPIOA, 6); break; - case 10: palSetPad(GPIOA, 7); break; - case 11: palSetPad(GPIOA, 3); break; - } + setPad(matrix_col_pins[col]); // need wait to settle pin state wait_us(20); - // read row data { B5, B10, A9, A8 } - data = ( - (palReadPad(GPIOB, 5) << 0 ) | - (palReadPad(GPIOB, 10) << 1 ) | - (palReadPad(GPIOA, 9) << 2 ) | - (palReadPad(GPIOA, 8) << 3 ) - ); - - // unstrobe col { B11, B10, B2, B1, A7, B0 } - switch (col) { - case 0: palClearPad(GPIOA, 10); break; - case 1: palClearPad(GPIOB, 2); break; - case 2: palClearPad(GPIOA, 15); break; - case 3: palClearPad(GPIOA, 0); break; - case 4: palClearPad(GPIOA, 1); break; - case 5: palClearPad(GPIOA, 2); break; - case 6: palClearPad(GPIOB, 0); break; - case 7: palClearPad(GPIOB, 1); break; - case 8: palClearPad(GPIOC, 13); break; - case 9: palClearPad(GPIOA, 6); break; - case 10: palClearPad(GPIOA, 7); break; - case 11: palClearPad(GPIOA, 3); break; + for (int row = 0; row < MATRIX_ROWS; row++) { + data |= (readPad(matrix_row_pins[row]) << row); } + clearPad(matrix_col_pins[col]); + if (matrix_debouncing[col] != data) { matrix_debouncing[col] = data; debouncing = true; diff --git a/quantum/config_common.h b/quantum/config_common.h index f6f51b367d..34cfefb088 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h @@ -23,6 +23,8 @@ #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */ #ifdef __AVR__ + #define LINE_TYPE uint8_t + /* I/O pins */ #ifndef F0 #define B0 0x30 @@ -74,8 +76,115 @@ #define A6 0x06 #define A7 0x07 #endif +#else + #include "hal.h" + + #define LINE_TYPE ioline_t + + #define A0 PAL_LINE(GPIOA, 0) + #define A1 PAL_LINE(GPIOA, 1) + #define A2 PAL_LINE(GPIOA, 2) + #define A3 PAL_LINE(GPIOA, 3) + #define A4 PAL_LINE(GPIOA, 4) + #define A5 PAL_LINE(GPIOA, 5) + #define A6 PAL_LINE(GPIOA, 6) + #define A7 PAL_LINE(GPIOA, 7) + #define A8 PAL_LINE(GPIOA, 8) + #define A9 PAL_LINE(GPIOA, 9) + #define A10 PAL_LINE(GPIOA, 10) + #define A11 PAL_LINE(GPIOA, 11) + #define A12 PAL_LINE(GPIOA, 12) + #define A13 PAL_LINE(GPIOA, 13) + #define A14 PAL_LINE(GPIOA, 14) + #define A15 PAL_LINE(GPIOA, 15) + #define B0 PAL_LINE(GPIOB, 0) + #define B1 PAL_LINE(GPIOB, 1) + #define B2 PAL_LINE(GPIOB, 2) + #define B3 PAL_LINE(GPIOB, 3) + #define B4 PAL_LINE(GPIOB, 4) + #define B5 PAL_LINE(GPIOB, 5) + #define B6 PAL_LINE(GPIOB, 6) + #define B7 PAL_LINE(GPIOB, 7) + #define B8 PAL_LINE(GPIOB, 8) + #define B9 PAL_LINE(GPIOB, 9) + #define B10 PAL_LINE(GPIOB, 10) + #define B11 PAL_LINE(GPIOB, 11) + #define B12 PAL_LINE(GPIOB, 12) + #define B13 PAL_LINE(GPIOB, 13) + #define B14 PAL_LINE(GPIOB, 14) + #define B15 PAL_LINE(GPIOB, 15) + #define C0 PAL_LINE(GPIOC, 0) + #define C1 PAL_LINE(GPIOC, 1) + #define C2 PAL_LINE(GPIOC, 2) + #define C3 PAL_LINE(GPIOC, 3) + #define C4 PAL_LINE(GPIOC, 4) + #define C5 PAL_LINE(GPIOC, 5) + #define C6 PAL_LINE(GPIOC, 6) + #define C7 PAL_LINE(GPIOC, 7) + #define C8 PAL_LINE(GPIOC, 8) + #define C9 PAL_LINE(GPIOC, 9) + #define C10 PAL_LINE(GPIOC, 10) + #define C11 PAL_LINE(GPIOC, 11) + #define C12 PAL_LINE(GPIOC, 12) + #define C13 PAL_LINE(GPIOC, 13) + #define C14 PAL_LINE(GPIOC, 14) + #define C15 PAL_LINE(GPIOC, 15) + #define D0 PAL_LINE(GPIOD, 0) + #define D1 PAL_LINE(GPIOD, 1) + #define D2 PAL_LINE(GPIOD, 2) + #define D3 PAL_LINE(GPIOD, 3) + #define D4 PAL_LINE(GPIOD, 4) + #define D5 PAL_LINE(GPIOD, 5) + #define D6 PAL_LINE(GPIOD, 6) + #define D7 PAL_LINE(GPIOD, 7) + #define D8 PAL_LINE(GPIOD, 8) + #define D9 PAL_LINE(GPIOD, 9) + #define D10 PAL_LINE(GPIOD, 10) + #define D11 PAL_LINE(GPIOD, 11) + #define D12 PAL_LINE(GPIOD, 12) + #define D13 PAL_LINE(GPIOD, 13) + #define D14 PAL_LINE(GPIOD, 14) + #define D15 PAL_LINE(GPIOD, 15) + #define E0 PAL_LINE(GPIOE, 0) + #define E1 PAL_LINE(GPIOE, 1) + #define E2 PAL_LINE(GPIOE, 2) + #define E3 PAL_LINE(GPIOE, 3) + #define E4 PAL_LINE(GPIOE, 4) + #define E5 PAL_LINE(GPIOE, 5) + #define E6 PAL_LINE(GPIOE, 6) + #define E7 PAL_LINE(GPIOE, 7) + #define E8 PAL_LINE(GPIOE, 8) + #define E9 PAL_LINE(GPIOE, 9) + #define E10 PAL_LINE(GPIOE, 10) + #define E11 PAL_LINE(GPIOE, 11) + #define E12 PAL_LINE(GPIOE, 12) + #define E13 PAL_LINE(GPIOE, 13) + #define E14 PAL_LINE(GPIOE, 14) + #define E15 PAL_LINE(GPIOE, 15) + #define F0 PAL_LINE(GPIOF, 0) + #define F1 PAL_LINE(GPIOF, 1) + #define F2 PAL_LINE(GPIOF, 2) + #define F3 PAL_LINE(GPIOF, 3) + #define F4 PAL_LINE(GPIOF, 4) + #define F5 PAL_LINE(GPIOF, 5) + #define F6 PAL_LINE(GPIOF, 6) + #define F7 PAL_LINE(GPIOF, 7) + #define F8 PAL_LINE(GPIOF, 8) + #define F9 PAL_LINE(GPIOF, 9) + #define F10 PAL_LINE(GPIOF, 10) + #define F11 PAL_LINE(GPIOF, 11) + #define F12 PAL_LINE(GPIOF, 12) + #define F13 PAL_LINE(GPIOF, 13) + #define F14 PAL_LINE(GPIOF, 14) + #define F15 PAL_LINE(GPIOF, 15) + + #define setPadMode(line, mode) palSetPadMode(PAL_PORT(line), PAL_PAD(line), mode) + #define setPad(line) palSetPad(PAL_PORT(line), PAL_PAD(line)) + #define clearPad(line) palClearPad(PAL_PORT(line), PAL_PAD(line)) + #define readPad(line) palReadPad(PAL_PORT(line), PAL_PAD(line)) #endif + /* USART configuration */ #ifdef BLUETOOTH_ENABLE # ifdef __AVR_ATmega32U4__ From ff4a1ae5d203095dedc7a6a6cc9a06bebe2818ed Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 3 Jun 2018 21:55:07 -0400 Subject: [PATCH 40/42] inital encoder implementation --- common_features.mk | 6 +++ keyboards/planck/light/rev1/config.h | 3 ++ keyboards/planck/light/rev1/rules.mk | 3 +- keyboards/planck/light/rev2/config.h | 6 ++- keyboards/planck/light/rev2/matrix.c | 31 ------------- keyboards/planck/light/rev2/rules.mk | 1 + quantum/config_common.h | 14 +++++- quantum/encoder.c | 67 ++++++++++++++++++++++++++++ quantum/encoder.h | 27 +++++++++++ quantum/quantum.c | 7 +++ quantum/quantum.h | 4 ++ 11 files changed, 135 insertions(+), 34 deletions(-) create mode 100644 quantum/encoder.c create mode 100644 quantum/encoder.h diff --git a/common_features.mk b/common_features.mk index a4e744bdb7..a76c522bfc 100644 --- a/common_features.mk +++ b/common_features.mk @@ -209,6 +209,12 @@ ifeq ($(strip $(I2C_SLAVE_ENABLE)), yes) OPT_DEFS += -DI2C_SLAVE_ENABLE endif +ifeq ($(strip $(ENCODER_ENABLE)), yes) + OPT_DEFS += -DENCODER_ENABLE + SRC += $(QUANTUM_DIR)/encoder.c +endif + + QUANTUM_SRC:= \ $(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/keymap_common.c \ diff --git a/keyboards/planck/light/rev1/config.h b/keyboards/planck/light/rev1/config.h index 17c015ed0f..b1f356c425 100644 --- a/keyboards/planck/light/rev1/config.h +++ b/keyboards/planck/light/rev1/config.h @@ -41,5 +41,8 @@ #define DRIVER_2_LED_TOTAL 24 #define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL +#define NUMBER_OF_ENCODERS 1 +#define ENCODERS_PAD_A { F6 } +#define ENCODERS_PAD_B { F7 } #endif diff --git a/keyboards/planck/light/rev1/rules.mk b/keyboards/planck/light/rev1/rules.mk index c10b8fd1da..4de2f21086 100644 --- a/keyboards/planck/light/rev1/rules.mk +++ b/keyboards/planck/light/rev1/rules.mk @@ -1,5 +1,6 @@ MIDI_ENABLE = yes AUDIO_ENABLE = yes # Audio output on port C6 RGB_MATRIX_ENABLE = yes +ENCODER_ENABLE = yes -MCU = at90usb1286 \ No newline at end of file +MCU = at90usb1286 diff --git a/keyboards/planck/light/rev2/config.h b/keyboards/planck/light/rev2/config.h index ebfb1ddea5..e8cf383c62 100644 --- a/keyboards/planck/light/rev2/config.h +++ b/keyboards/planck/light/rev2/config.h @@ -52,8 +52,12 @@ #undef AUDIO_VOICES #undef C6_AUDIO +#define NUMBER_OF_ENCODERS 1 +#define ENCODERS_PAD_A { B12 } +#define ENCODERS_PAD_B { B13 } + /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ -#define DEBOUNCE 6 +#define DEBOUNCE 0 /* Prevent modifiers from being stuck on after layer changes. */ #define PREVENT_STUCK_MODIFIERS diff --git a/keyboards/planck/light/rev2/matrix.c b/keyboards/planck/light/rev2/matrix.c index 0a0f84ece3..0de8b20285 100644 --- a/keyboards/planck/light/rev2/matrix.c +++ b/keyboards/planck/light/rev2/matrix.c @@ -21,10 +21,6 @@ static matrix_row_t matrix_debouncing[MATRIX_COLS]; static bool debouncing = false; static uint16_t debouncing_time = 0; -static uint8_t encoder_state = 0; -static int8_t encoder_value = 0; -static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; - static LINE_TYPE matrix_col_pins[MATRIX_COLS] = MATRIX_COL_PINS; static LINE_TYPE matrix_row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; @@ -48,12 +44,6 @@ void matrix_init(void) { printf("matrix init\n"); //debug_matrix = true; - // encoder setup - palSetPadMode(GPIOB, 12, PAL_MODE_INPUT_PULLUP); - palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_PULLUP); - - encoder_state = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); - // actual matrix setup for (int i = 0; i < MATRIX_COLS; i++) { setPadMode(matrix_col_pins[i], PAL_MODE_OUTPUT_PUSHPULL); @@ -69,29 +59,8 @@ void matrix_init(void) { matrix_init_quantum(); } -__attribute__ ((weak)) -void encoder_update(bool clockwise) { } - -#ifndef ENCODER_RESOLUTION - #define ENCODER_RESOLUTION 4 -#endif - -#define COUNTRECLOCKWISE 0 -#define CLOCKWISE 1 - uint8_t matrix_scan(void) { - // encoder on B12 and B13 - encoder_state <<= 2; - encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); - encoder_value += encoder_LUT[encoder_state & 0xF]; - if (encoder_value >= ENCODER_RESOLUTION) { - encoder_update(COUNTRECLOCKWISE); - } - if (encoder_value <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise - encoder_update(CLOCKWISE); - } - encoder_value %= ENCODER_RESOLUTION; // actual matrix for (int col = 0; col < MATRIX_COLS; col++) { diff --git a/keyboards/planck/light/rev2/rules.mk b/keyboards/planck/light/rev2/rules.mk index f037375bc1..4d90354c95 100644 --- a/keyboards/planck/light/rev2/rules.mk +++ b/keyboards/planck/light/rev2/rules.mk @@ -53,4 +53,5 @@ NKRO_ENABLE = yes # USB Nkey Rollover CUSTOM_MATRIX = yes # Custom matrix file AUDIO_ENABLE = yes RGB_MATRIX_ENABLE = yes +ENCODER_ENABLE = yes # SERIAL_LINK_ENABLE = yes diff --git a/quantum/config_common.h b/quantum/config_common.h index 34cfefb088..5de2d13993 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2017 Jack Humbert +/* Copyright 2015-2018 Jack Humbert * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */ #ifdef __AVR__ + #include #define LINE_TYPE uint8_t /* I/O pins */ @@ -76,6 +77,15 @@ #define A6 0x06 #define A7 0x07 #endif + + #define setPadMode(line, mode) _SFR_IO8((line >> 4) + 1) mode _BV(line & 0xF) + #define setPad(line) _SFR_IO8((line >> 4) + 2) |= _BV(line & 0xF) + #define clearPad(line) _SFR_IO8((line >> 4) + 2) &= ~_BV(line & 0xF) + #define readPad(line) (_SFR_IO8(line >> 4) & _BV(line & 0xF)) + + #define PAD_MODE_INPUT &= ~ + #define PAD_MODE_OUTPUT |= + #else #include "hal.h" @@ -182,6 +192,8 @@ #define setPad(line) palSetPad(PAL_PORT(line), PAL_PAD(line)) #define clearPad(line) palClearPad(PAL_PORT(line), PAL_PAD(line)) #define readPad(line) palReadPad(PAL_PORT(line), PAL_PAD(line)) + + #define PAD_MODE_INPUT PAL_MODE_INPUT_PULLUP #endif diff --git a/quantum/encoder.c b/quantum/encoder.c new file mode 100644 index 0000000000..022cc1c01c --- /dev/null +++ b/quantum/encoder.c @@ -0,0 +1,67 @@ +/* + * Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "encoder.h" +#include + +#ifndef ENCODER_RESOLUTION + #define ENCODER_RESOLUTION 4 +#endif + +#if !defined(ENCODERS_PAD_A) || !defined(ENCODERS_PAD_B) + #error "No encoder pads defined by ENCODERS_PAD_A and ENCODERS_PAD_B" +#endif + +static LINE_TYPE encoders_pad_a[NUMBER_OF_ENCODERS] = ENCODERS_PAD_A; +static LINE_TYPE encoders_pad_b[NUMBER_OF_ENCODERS] = ENCODERS_PAD_B; + +static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; + +static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; +static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; + +__attribute__ ((weak)) +void encoder_update_user(bool clockwise) { } + +__attribute__ ((weak)) +void encoder_update_kb(bool clockwise) { + encoder_update_user(clockwise); +} + +void encoder_init(void) { + for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { + setPadMode(encoders_pad_a[i], PAD_MODE_INPUT); + setPadMode(encoders_pad_b[i], PAD_MODE_INPUT); + + encoder_state[i] = (readPad(encoders_pad_a[i]) << 0) | (readPad(encoders_pad_b[i]) << 1); + } +} + +void encoder_read(void) { + for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { + encoder_state[i] <<= 2; + encoder_state[i] |= (readPad(encoders_pad_a[i]) << 0) | (readPad(encoders_pad_b[i]) << 1); + encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF]; + if (encoder_value[i] >= ENCODER_RESOLUTION) { + encoder_update_kb(COUNTRECLOCKWISE); + } + if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + encoder_update_kb(CLOCKWISE); + } + encoder_value[i] %= ENCODER_RESOLUTION; + } +} diff --git a/quantum/encoder.h b/quantum/encoder.h new file mode 100644 index 0000000000..bf2c73bc24 --- /dev/null +++ b/quantum/encoder.h @@ -0,0 +1,27 @@ +/* + * Copyright 2018 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ENCODER_H +#define ENCODER_H + +#define COUNTRECLOCKWISE 0 +#define CLOCKWISE 1 + +void encoder_init(void); +void encoder_read(void); + +#endif diff --git a/quantum/quantum.c b/quantum/quantum.c index f9b3e2197d..331ed5634c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -851,6 +851,9 @@ void matrix_init_quantum() { #ifdef RGB_MATRIX_ENABLE rgb_matrix_init_drivers(); #endif + #ifdef ENCODER_ENABLE + encoder_init(); + #endif matrix_init_kb(); } @@ -885,6 +888,10 @@ void matrix_scan_quantum() { rgb_matrix_task_counter = ((rgb_matrix_task_counter + 1) % (RGB_MATRIX_SKIP_FRAMES + 1)); #endif + #ifdef ENCODER_ENABLE + encoder_read(); + #endif + matrix_scan_kb(); } #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN) diff --git a/quantum/quantum.h b/quantum/quantum.h index 36eeedd494..55ea4a5010 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -121,6 +121,10 @@ extern uint32_t default_layer_state; #include "process_terminal_nop.h" #endif +#ifdef ENCODER_ENABLE + #include "encoder.h" +#endif + #ifndef MIN #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) From 21665df8ebefd05be097f4ce5139174ca36618cd Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 3 Jun 2018 22:58:59 -0400 Subject: [PATCH 41/42] add encoder docs --- docs/_summary.md | 1 + docs/feature_encoders.md | 41 +++++++++++++++++++++++ keyboards/planck/keymaps/default/keymap.c | 2 +- quantum/encoder.c | 10 +++--- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 docs/feature_encoders.md diff --git a/docs/_summary.md b/docs/_summary.md index 318c526a85..75bc5cc784 100644 --- a/docs/_summary.md +++ b/docs/_summary.md @@ -34,6 +34,7 @@ * [Bootmagic](feature_bootmagic.md) * [Command](feature_command.md) * [Dynamic Macros](feature_dynamic_macros.md) + * [Encoders](feature_encoders.md) * [Grave Escape](feature_grave_esc.md) * [Key Lock](feature_key_lock.md) * [Layouts](feature_layouts.md) diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md new file mode 100644 index 0000000000..f482eefec8 --- /dev/null +++ b/docs/feature_encoders.md @@ -0,0 +1,41 @@ +# Encoders + +Basic encoders are supported by adding this to your `rules.mk`: + + ENCODER_ENABLE = yes + +and this to your `config.h`: + + #define NUMBER_OF_ENCODERS 1 + #define ENCODERS_PAD_A { B12 } + #define ENCODERS_PAD_B { B13 } + +Each PAD_A/B variable defines an array so multiple encoders can be defined, e.g.: + + #define ENCODERS_PAD_A { encoder1a, encoder2a } + #define ENCODERS_PAD_B { encoder1a, encoder2b } + +If your encoder's clockwise directions are incorrect, you can swap the A & B pad definitions. + +Additionally, the resolution can be specified in the same file (the default & suggested is 4): + + #define ENCODER_RESOLUTION 4 + +## Callbacks + +The callback functions can be inserted into your `.c`: + + void encoder_update_kb(uint8_t index, bool clockwise) { + encoder_update_user(index, clockwise); + } + +or `keymap.c`: + + void encoder_update_user(uint8_t index, bool clockwise) { + + } + + +## Hardware + +The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground. diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index 545ca42299..8c452c8dfb 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -259,7 +259,7 @@ uint16_t muse_counter = 0; uint8_t muse_offset = 70; uint16_t muse_tempo = 50; -void encoder_update(bool clockwise) { +void encoder_update_user(int8_t index, bool clockwise) { if (muse_mode) { if (IS_LAYER_ON(_RAISE)) { if (clockwise) { diff --git a/quantum/encoder.c b/quantum/encoder.c index 022cc1c01c..103ff8289b 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -35,11 +35,11 @@ static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; __attribute__ ((weak)) -void encoder_update_user(bool clockwise) { } +void encoder_update_user(int8_t index, bool clockwise) { } __attribute__ ((weak)) -void encoder_update_kb(bool clockwise) { - encoder_update_user(clockwise); +void encoder_update_kb(int8_t index, bool clockwise) { + encoder_update_user(index, clockwise); } void encoder_init(void) { @@ -57,10 +57,10 @@ void encoder_read(void) { encoder_state[i] |= (readPad(encoders_pad_a[i]) << 0) | (readPad(encoders_pad_b[i]) << 1); encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF]; if (encoder_value[i] >= ENCODER_RESOLUTION) { - encoder_update_kb(COUNTRECLOCKWISE); + encoder_update_kb(i, COUNTRECLOCKWISE); } if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise - encoder_update_kb(CLOCKWISE); + encoder_update_kb(i, CLOCKWISE); } encoder_value[i] %= ENCODER_RESOLUTION; } From a6afb16c90169827bd350723a2d530e75de94052 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 4 Jun 2018 00:50:09 -0400 Subject: [PATCH 42/42] fix assembly errors with hal --- keyboards/planck/light/rev2/matrix.c | 1 + quantum/config_common.h | 20 +----------------- quantum/encoder.c | 2 +- quantum/quantum.h | 31 +++++++++++++++++++++++++--- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/keyboards/planck/light/rev2/matrix.c b/keyboards/planck/light/rev2/matrix.c index 0de8b20285..5982741b66 100644 --- a/keyboards/planck/light/rev2/matrix.c +++ b/keyboards/planck/light/rev2/matrix.c @@ -10,6 +10,7 @@ #include "action.h" #include "keycode.h" #include +#include "quantum.h" /* * col: { A10, B2, A15, A0, A1, A2, B0, B1, C13, A6, A7, A3 } diff --git a/quantum/config_common.h b/quantum/config_common.h index 5de2d13993..7c02e9e5f3 100644 --- a/quantum/config_common.h +++ b/quantum/config_common.h @@ -23,8 +23,6 @@ #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */ #ifdef __AVR__ - #include - #define LINE_TYPE uint8_t /* I/O pins */ #ifndef F0 @@ -78,18 +76,8 @@ #define A7 0x07 #endif - #define setPadMode(line, mode) _SFR_IO8((line >> 4) + 1) mode _BV(line & 0xF) - #define setPad(line) _SFR_IO8((line >> 4) + 2) |= _BV(line & 0xF) - #define clearPad(line) _SFR_IO8((line >> 4) + 2) &= ~_BV(line & 0xF) - #define readPad(line) (_SFR_IO8(line >> 4) & _BV(line & 0xF)) - #define PAD_MODE_INPUT &= ~ - #define PAD_MODE_OUTPUT |= - -#else - #include "hal.h" - - #define LINE_TYPE ioline_t +#elif defined(__arm__) #define A0 PAL_LINE(GPIOA, 0) #define A1 PAL_LINE(GPIOA, 1) @@ -188,12 +176,6 @@ #define F14 PAL_LINE(GPIOF, 14) #define F15 PAL_LINE(GPIOF, 15) - #define setPadMode(line, mode) palSetPadMode(PAL_PORT(line), PAL_PAD(line), mode) - #define setPad(line) palSetPad(PAL_PORT(line), PAL_PAD(line)) - #define clearPad(line) palClearPad(PAL_PORT(line), PAL_PAD(line)) - #define readPad(line) palReadPad(PAL_PORT(line), PAL_PAD(line)) - - #define PAD_MODE_INPUT PAL_MODE_INPUT_PULLUP #endif diff --git a/quantum/encoder.c b/quantum/encoder.c index 103ff8289b..265e0ec206 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -16,7 +16,7 @@ */ #include "encoder.h" -#include +#include "quantum.h" #ifndef ENCODER_RESOLUTION #define ENCODER_RESOLUTION 4 diff --git a/quantum/quantum.h b/quantum/quantum.h index 55ea4a5010..b634ab7418 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -17,10 +17,11 @@ #define QUANTUM_H #if defined(__AVR__) -#include -#include -#include + #include + #include + #include #endif + #include "wait.h" #include "matrix.h" #include "keymap.h" @@ -130,6 +131,30 @@ extern uint32_t default_layer_state; #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #endif + +#ifdef __AVR__ + #include + #define LINE_TYPE uint8_t + + #define setPadMode(line, mode) _SFR_IO8((line >> 4) + 1) mode _BV(line & 0xF) + #define setPad(line) _SFR_IO8((line >> 4) + 2) |= _BV(line & 0xF) + #define clearPad(line) _SFR_IO8((line >> 4) + 2) &= ~_BV(line & 0xF) + #define readPad(line) (_SFR_IO8(line >> 4) & _BV(line & 0xF)) + + #define PAD_MODE_INPUT &= ~ + #define PAD_MODE_OUTPUT |= +#elif defined(__arm__) + #include "hal.h" + #define LINE_TYPE ioline_t + + #define setPadMode(line, mode) palSetPadMode(PAL_PORT(line), PAL_PAD(line), mode) + #define setPad(line) palSetPad(PAL_PORT(line), PAL_PAD(line)) + #define clearPad(line) palClearPad(PAL_PORT(line), PAL_PAD(line)) + #define readPad(line) palReadPad(PAL_PORT(line), PAL_PAD(line)) + + #define PAD_MODE_INPUT PAL_MODE_INPUT_PULLUP +#endif + #define STRINGIZE(z) #z #define ADD_SLASH_X(y) STRINGIZE(\x ## y) #define SYMBOL_STR(x) ADD_SLASH_X(x)