Browse Source

music map init, dip scan added

pull/2666/head
Jack Humbert 6 years ago
parent
commit
91efe74365
10 changed files with 96 additions and 48 deletions
  1. +7
    -0
      keyboards/planck/planck.c
  2. +1
    -1
      keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h
  3. +5
    -1
      keyboards/planck/rev6/config.h
  4. +28
    -7
      keyboards/planck/rev6/matrix.c
  5. +1
    -1
      keyboards/planck/rev6/mcuconf.h
  6. +2
    -2
      keyboards/planck/rev6/rev6.c
  7. +19
    -19
      quantum/audio/audio_arm.c
  8. +21
    -12
      quantum/process_keycode/process_music.c
  9. +5
    -0
      quantum/process_keycode/process_music.h
  10. +7
    -5
      tmk_core/protocol/chibios/usb_main.c

+ 7
- 0
keyboards/planck/planck.c View File

@ -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
);

+ 1
- 1
keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h View File

@ -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) | \


+ 5
- 1
keyboards/planck/rev6/config.h View File

@ -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


+ 28
- 7
keyboards/planck/rev6/matrix.c View File

@ -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;


+ 1
- 1
keyboards/planck/rev6/mcuconf.h View File

@ -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


+ 2
- 2
keyboards/planck/rev6/rev6.c View File

@ -16,9 +16,9 @@
#include "rev6.h"
void matrix_init_kb(void) {
matrix_init_user();
}
void matrix_scan_kb(void) {
matrix_scan_user();
}

+ 19
- 19
quantum/audio/audio_arm.c View File

@ -204,6 +204,21 @@ 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,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
@ -218,23 +233,8 @@ 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
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/*
@ -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) {


+ 21
- 12
quantum/process_keycode/process_music.c View File

@ -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);


+ 5
- 0
quantum/process_keycode/process_music.h View File

@ -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);


+ 7
- 5
tmk_core/protocol/chibios/usb_main.c View File

@ -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();
}


Loading…
Cancel
Save