From 52f671c23eaeff9547e2a02154f0a056278b113c Mon Sep 17 00:00:00 2001 From: jpetermans Date: Mon, 8 May 2017 11:57:40 -0700 Subject: [PATCH] small code cleanup --- keyboards/infinity60/MEMO.txt | 385 ------------------------- keyboards/infinity60/led_controller.c | 389 ++++++++++++++------------ keyboards/infinity60/led_controller.h | 16 +- 3 files changed, 212 insertions(+), 578 deletions(-) delete mode 100644 keyboards/infinity60/MEMO.txt diff --git a/keyboards/infinity60/MEMO.txt b/keyboards/infinity60/MEMO.txt deleted file mode 100644 index e2886aa00..000000000 --- a/keyboards/infinity60/MEMO.txt +++ /dev/null @@ -1,385 +0,0 @@ -flabbergast's TMK/ChibiOS port -============================== -2015/10/16 - - -Build ------ -$ git clone -b chibios https://github.com/flabbergast/tmk_keyboard.git - -$ cd tmk_keyboard -$ git submodule add -f -b kinetis https://github.com/flabbergast/ChibiOS.git tmk_core/tool/chibios/chibios -or -$ cd tmk_keyboard/tmk_core/tool/chibios -$ git clone -b kinetis https://github.com/flabbergast/ChibiOS.git tmk_core/tool/chibios/chibios - -$ cd tmk_keyboard/keyboard/infinity_chibios -$ make - - - - -Chibios Configuration ---------------------- -halconf.h: for HAL configuration - placed in project directory - read in chibios/os/hal/hal.mk - included in chibios/os/hal/include/hal.h -mcuconf.h: for MCU configuration - placed in project directory - included in halconf.h - - -Chibios Term ------------- -PAL = Port Abstraction Layer - palWritePad - palReadPad - palSetPad - chibios/os/hal/include/pal.h - -LLD = Low Level Driver - - -Makefile --------- - # /os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) - MCU_FAMILY = KINETIS - MCU_SERIES = KL2x - - # - it should exist either in /os/common/ports/ARMCMx/compilers/GCC/ld/ - # or /ld/ - MCU_LDSCRIPT = MKL26Z64 - - # - it should exist in /os/common/ports/ARMCMx/compilers/GCC/mk/ - MCU_STARTUP = kl2x - - # Board: it should exist either in /os/hal/boards/ - # or /boards - BOARD = PJRC_TEENSY_LC - - MCU = cortex-m0 - - # ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7 - ARMV = 6 - - -halconf.h ---------- - - -mcuconf.h ---------- - - -chconf.h --------- - - -ld script ---------- ---- ../../tmk_core/tool/chibios/chibios/os/common/ports/ARMCMx/compilers/GCC/ld/MKL26Z64.ld 2015-10-15 09:08:58.732904304 +0900 -+++ ld/MKL26Z64.ld 2015-10-15 08:48:06.430215496 +0900 -@@ -27,7 +27,8 @@ - { - flash0 : org = 0x00000000, len = 0xc0 - flashcfg : org = 0x00000400, len = 0x10 -- flash : org = 0x00000410, len = 64k - 0x410 -+ flash : org = 0x00000410, len = 62k - 0x410 -+ eeprom_emu : org = 0x0000F800, len = 2k - ram : org = 0x1FFFF800, len = 8k - } - -@@ -35,6 +36,10 @@ - __ram_size__ = LENGTH(ram); - __ram_end__ = __ram_start__ + __ram_size__; - -+__eeprom_workarea_start__ = ORIGIN(eeprom_emu); -+__eeprom_workarea_size__ = LENGTH(eeprom_emu); -+__eeprom_workarea_end__ = __eeprom_workarea_start__ + __eeprom_workarea_size__; -+ - SECTIONS - { - . = 0; - - - -Configuration/Startup for Infinity 60% --------------------------------------- -Configuration: - - -Clock: -Inifinity - FEI(FLL Engaged Internal) mode with core clock:48MHz, bus clock:48MHz, flash clock:24MHz - Clock dividor: - SIM_CLKDIV1[OUTDIV1] = 0 divide-by-1 for core clock - SIM_CLKDIV1[OUTDIV2] = 0 divide-by-1 for bus clock - SIM_CLKDIV1[OUTDIV4] = 1 divide-by-2 for flash clock - Internal reference clock: - MCG_C1[IREFS] = 1 Internal Reference Select for clock source for FLL - MCG_C1[IRCLKEN] = 1 Internal Reference Clock Enable - FLL multipilication: - MCG_C4[DMX32] = 1 - MCG_C4[DRST_DRS] = 01 FLL factor 1464 * 32.768kHz = 48MHz - -chibios/os/hal/ports/KINETIS/K20x/hal_lld.c - k20x_clock_init(): called in __early_init() defined in board.c - disable watchdog and configure clock - - configurable macros: - KINETIS_NO_INIT: whether init or not - KINETIS_MCG_MODE: clock mode - KINETIS_MCG_MODE_FEI - KINETIS_MCG_MODE_PEE - hal/ports/KINETIS/K20x/hal_lld.h - - -chibios/os/hal/boards/FREESCALE_FREEDOM_K20D50M/board.h - PALConfig pal_default_config - boardInit() - __early_init() - macro definitions for board infos, freq and mcu type - -chibios/os/hal/boards/FREESCALE_FREEDOM_K20D50M/board.c - -USB - - -Startup -------- - common/ports/ARMCMx/GCC/crt0_v[67]m.s - Reset_Handler: startup code - common/ports/ARMCMx/GCC/crt1.c - __core_init(): weak - __early_init(): weak - __late_init(): weak - __default_exit(): weak - called from Reset_Handler of crt0 - common/ports/ARMCMx/GCC/vector.c - common/ports/ARMCMx/GCC/ld/*.ld - -chibios/os/common/ports/ARMCMx/compilers/GCC/ -├── crt0_v6m.s -├── crt0_v7m.s -├── crt1.c -├── ld -│   ├── MK20DX128BLDR3.ld -│   ├── MK20DX128BLDR4.ld -│   ├── MK20DX128.ld -│   ├── MK20DX256.ld -│   ├── MKL25Z128.ld -│   ├── MKL26Z128.ld -│   ├── MKL26Z64.ld -│   └── STM32L476xG.ld -├── mk -│   ├── startup_k20x5.mk -│   ├── startup_k20x7.mk -│   ├── startup_k20x.mk -│   ├── startup_kl2x.mk -│   └── startup_stm32l4xx.mk -├── rules.ld -├── rules.mk -└── vectors.c - -chibios/os/hal/ -├── boards -│   ├── FREESCALE_FREEDOM_K20D50M -│   │   ├── board.c -│   │   ├── board.h -│   │   └── board.mk -│   ├── MCHCK_K20 -│   │   ├── board.c -│   │   ├── board.h -│   │   └── board.mk -│   ├── PJRC_TEENSY_3 -│   │   ├── board.c -│   │   ├── board.h -│   │   └── board.mk -│   ├── PJRC_TEENSY_3_1 -│   │   ├── board.c -│   │   ├── board.h -│   │   └── board.mk -│   ├── PJRC_TEENSY_LC -│   │   ├── board.c -│   │   ├── board.h -│   │   └── board.mk -│   ├── readme.txt -│   ├── simulator -│   │   ├── board.c -│   │   ├── board.h -│   │   └── board.mk -│   ├── ST_NUCLEO_F030R8 -│   │   ├── board.c -│   │   ├── board.h -│   │   ├── board.mk -│   │   └── cfg -│   │   └── board.chcfg -├── hal.mk -├── include -│   ├── adc.h -│   ├── can.h -│   ├── dac.h -│   ├── ext.h -│   ├── gpt.h -│   ├── hal_channels.h -│   ├── hal_files.h -│   ├── hal.h -│   ├── hal_ioblock.h -│   ├── hal_mmcsd.h -│   ├── hal_queues.h -│   ├── hal_streams.h -│   ├── i2c.h -│   ├── i2s.h -│   ├── icu.h -│   ├── mac.h -│   ├── mii.h -│   ├── mmc_spi.h -│   ├── pal.h -│   ├── pwm.h -│   ├── rtc.h -│   ├── sdc.h -│   ├── serial.h -│   ├── serial_usb.h -│   ├── spi.h -│   ├── st.h -│   ├── uart.h -│   └── usb.h -├── lib -│   └── streams -│   ├── chprintf.c -│   ├── chprintf.h -│   ├── memstreams.c -│   ├── memstreams.h -│   ├── nullstreams.c -│   └── nullstreams.h -├── osal -│   ├── nil -│   │   ├── osal.c -│   │   ├── osal.h -│   │   └── osal.mk -│   ├── os-less -│   │   └── ARMCMx -│   │   ├── osal.c -│   │   ├── osal.h -│   │   └── osal.mk -│   └── rt -│   ├── osal.c -│   ├── osal.h -│   └── osal.mk -├── ports -│   ├── AVR -│   ├── common -│   │   └── ARMCMx -│   │   ├── mpu.h -│   │   ├── nvic.c -│   │   └── nvic.h -│   ├── KINETIS -│   │   ├── K20x -│   │   │   ├── hal_lld.c -│   │   │   ├── hal_lld.h -│   │   │   ├── kinetis_registry.h -│   │   │   ├── platform.dox -│   │   │   ├── platform.mk -│   │   │   ├── pwm_lld.c -│   │   │   ├── pwm_lld.h -│   │   │   ├── spi_lld.c -│   │   │   └── spi_lld.h -│   │   ├── KL2x -│   │   │   ├── hal_lld.c -│   │   │   ├── hal_lld.h -│   │   │   ├── kinetis_registry.h -│   │   │   ├── platform.mk -│   │   │   ├── pwm_lld.c -│   │   │   └── pwm_lld.h -│   │   ├── LLD -│   │   │   ├── adc_lld.c -│   │   │   ├── adc_lld.h -│   │   │   ├── ext_lld.c -│   │   │   ├── ext_lld.h -│   │   │   ├── gpt_lld.c -│   │   │   ├── gpt_lld.h -│   │   │   ├── i2c_lld.c -│   │   │   ├── i2c_lld.h -│   │   │   ├── pal_lld.c -│   │   │   ├── pal_lld.h -│   │   │   ├── serial_lld.c -│   │   │   ├── serial_lld.h -│   │   │   ├── st_lld.c -│   │   │   ├── st_lld.h -│   │   │   ├── usb_lld.c -│   │   │   └── usb_lld.h -│   │   └── README.md -│   ├── LPC -│   ├── simulator -│   └── STM32 -├── src -│   ├── adc.c -│   ├── can.c -│   ├── dac.c -│   ├── ext.c -│   ├── gpt.c -│   ├── hal.c -│   ├── hal_mmcsd.c -│   ├── hal_queues.c -│   ├── i2c.c -│   ├── i2s.c -│   ├── icu.c -│   ├── mac.c -│   ├── mmc_spi.c -│   ├── pal.c -│   ├── pwm.c -│   ├── rtc.c -│   ├── sdc.c -│   ├── serial.c -│   ├── serial_usb.c -│   ├── spi.c -│   ├── st.c -│   ├── uart.c -│   └── usb.c -└── templates - ├── adc_lld.c - ├── adc_lld.h - ├── can_lld.c - ├── can_lld.h - ├── dac_lld.c - ├── dac_lld.h - ├── ext_lld.c - ├── ext_lld.h - ├── gpt_lld.c - ├── gpt_lld.h - ├── halconf.h - ├── hal_lld.c - ├── hal_lld.h - ├── i2c_lld.c - ├── i2c_lld.h - ├── i2s_lld.c - ├── i2s_lld.h - ├── icu_lld.c - ├── icu_lld.h - ├── mac_lld.c - ├── mac_lld.h - ├── mcuconf.h - ├── osal - │   ├── osal.c - │   ├── osal.h - │   └── osal.mk - ├── pal_lld.c - ├── pal_lld.h - ├── platform.mk - ├── pwm_lld.c - ├── pwm_lld.h - ├── rtc_lld.c - ├── rtc_lld.h - ├── sdc_lld.c - ├── sdc_lld.h - ├── serial_lld.c - ├── serial_lld.h - ├── spi_lld.c - ├── spi_lld.h - ├── st_lld.c - ├── st_lld.h - ├── uart_lld.c - ├── uart_lld.h - ├── usb_lld.c - └── usb_lld.h diff --git a/keyboards/infinity60/led_controller.c b/keyboards/infinity60/led_controller.c index 59ca833b6..c162e9a8f 100644 --- a/keyboards/infinity60/led_controller.c +++ b/keyboards/infinity60/led_controller.c @@ -72,8 +72,6 @@ along with this program. If not, see . #define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS #endif -#define DEBUG_ENABLED 1 - /* ================= * ChibiOS I2C setup * ================= */ @@ -145,7 +143,6 @@ void is31_init(void) { __builtin_memset(full_page,0,0xB4+1); // zero function page, all registers (assuming full_page is all zeroes) is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1); - // disable hardware shutdown palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(GPIOB, 16); chThdSleepMilliseconds(10); @@ -182,7 +179,7 @@ static THD_FUNCTION(LEDthread, arg) { uint8_t pwm_step_status, page_status; //mailbox variables - uint8_t temp, msg_type, msg_led; + uint8_t temp, msg_type, msg_pin, msg_col, msg_led; msg_t msg; /* //control register variables @@ -199,14 +196,17 @@ page_status = 0; //start frame 0 (all off/on) // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't // be processed right away) chMBFetch(&led_mailbox, &msg, TIME_INFINITE); - msg_type = (msg >> 8) & 0xFF; //first byte is msg type - msg_led = (msg) & 0xFF; //second byte is action information + msg_col = (msg >> 24) & 0xFF;//if needed + msg_pin = (msg >> 16) & 0XFF;//if needed (SET_FULL_ROW) + msg_type = (msg >> 8) & 0xFF; //second byte is msg type + msg_led = (msg) & 0xFF; //first byte is action information xprintf("--------------------\n"); - chThdSleepMilliseconds(10); xprintf("mailbox fetch\nmsg: %X\n", msg); - chThdSleepMilliseconds(10); - xprintf("type: %X - led: %X\n", msg_type, msg_led); + chThdSleepMilliseconds(20); + xprintf("type: %X - pin: %X\n", msg_type, msg_pin); + chThdSleepMilliseconds(20); + xprintf("col: %X - led: %X\n", msg_col, msg_led); chThdSleepMilliseconds(10); switch (msg_type){ @@ -214,8 +214,12 @@ page_status = 0; //start frame 0 (all off/on) //TODO: lighting key led on keypress break; - //TODO: BLINK_ON/OFF_LED - break; + case SET_FULL_ROW: + //write full byte to pin address, msg_pin = pin #, msg_led = byte to write + //writes only to current page + xprintf("SET_FULL_ROW\n"); + write_led_byte(page_status,msg_pin,msg_led); + break; case OFF_LED: //on/off/toggle single led, msg_led = row/col of led @@ -255,6 +259,7 @@ page_status = 0; //start frame 0 (all off/on) chThdSleepMilliseconds(10); set_led_bit(7, control_register_word, msg_led, 6); is31_write_data (7, control_register_word, 0x02); + break; case TOGGLE_ALL: xprintf("TOGGLE_ALL: %d\n", msg_led); @@ -272,17 +277,12 @@ page_status = 0; //start frame 0 (all off/on) if (page_status > 0) { is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0); - } - //maintain lock leds - if (host_keyboard_leds() & (1< 0 && j % 9 == 0){ - xprintf("\n"); - } - switch (j) { - case 0: - xprintf("\n--on-off--\n"); - chThdSleepMilliseconds(2); - break; - case 0x12: - xprintf("\n--blink--\n"); - chThdSleepMilliseconds(2); - break; - } - is31_read_register(pages[i],j,&temp); - xprintf("%02X, ", temp); - chThdSleepMilliseconds(2); - } + } +} - xprintf("\n--pwm--\n"); - chThdSleepMilliseconds(2); - for(j=0x24;j<0xB4;j++) { - is31_read_register(pages[i],j,&temp); - xprintf("%02X, ", temp); - chThdSleepMilliseconds(2); - if(j > 0x24 && (j-4) % 8 == 0){ - xprintf("\n"); - } - } - xprintf("\n"); - } - - //Function Register - xprintf("\n--FUNCTION--\n"); - chThdSleepMilliseconds(2); - for(j=0;j<0x0D;j++) { - is31_read_register(0x0B,j,&temp); - switch(j) { - case 0: - xprintf("Config %02X", temp); - chThdSleepMilliseconds(2); - break; - case 1: - xprintf(" - Pict %02X\n", temp); - chThdSleepMilliseconds(2); - break; - case 2: - xprintf("Auto1 %02X", temp); - chThdSleepMilliseconds(2); - break; - case 3: - xprintf(" - Auto2 %02X\n", temp); - chThdSleepMilliseconds(2); - break; - case 5: - xprintf("Disp %02X", temp); - chThdSleepMilliseconds(2); - break; - case 6: - xprintf(" - Audio %02X\n", temp); - chThdSleepMilliseconds(2); - break; - case 7: - xprintf("Frame %02X", temp); - chThdSleepMilliseconds(2); - break; - case 8: - xprintf(" - Breath1 %02X\n", temp); - chThdSleepMilliseconds(2); - break; - case 9: - xprintf("Breath2 %02X - ", temp); - chThdSleepMilliseconds(2); - break; - case 10: - xprintf(" - Shut %02X\n", temp); - chThdSleepMilliseconds(2); - break; - case 11: - xprintf("AGC %02X", temp); - chThdSleepMilliseconds(2); - break; - case 12: - xprintf(" - ADC %02X\n", temp); - chThdSleepMilliseconds(2); - break; - } +/* ============================== + * debug function + * ============================== */ +void print_debug(uint8_t page) { + uint8_t j, debug_temp; + //debugging code - print full led/blink/pwm registers on each frame + xprintf("----layer state----: %X\n", layer_state); + xprintf("page: %d\n", page); + chThdSleepMilliseconds(10); + for(j=0;j<0x24;j++){ + if(j > 0 && j % 9 == 0){ + xprintf("\n"); + } + switch (j) { + case 0: + xprintf("\n--on-off--\n"); + chThdSleepMilliseconds(10); + break; + case 0x12: + xprintf("\n--blink--\n"); + chThdSleepMilliseconds(10); + break; + } + is31_read_register(page,j,&debug_temp); + xprintf("%02X, ", debug_temp); + chThdSleepMilliseconds(10); + } + + xprintf("\n--pwm--\n"); + chThdSleepMilliseconds(10); + for(j=0x24;j<0xB4;j++) { + is31_read_register(page,j,&debug_temp); + xprintf("%02X, ", debug_temp); + chThdSleepMilliseconds(10); + if(j > 0x24 && (j-3) % 8 == 0){ + xprintf("\n"); + } + } + xprintf("\n"); + + //Function Register + xprintf("\n--FUNCTION--\n"); + chThdSleepMilliseconds(10); + for(j=0;j<0x0D;j++) { + is31_read_register(0x0B,j,&debug_temp); + switch(j) { + case 0: + xprintf("Config %02X", debug_temp); + chThdSleepMilliseconds(2); + break; + case 1: + xprintf(" - Pict %02X\n", debug_temp); + chThdSleepMilliseconds(2); + break; + case 2: + xprintf("Auto1 %02X", debug_temp); + chThdSleepMilliseconds(2); + break; + case 3: + xprintf(" - Auto2 %02X\n", debug_temp); + chThdSleepMilliseconds(2); + break; + case 5: + xprintf("Disp %02X", debug_temp); + chThdSleepMilliseconds(2); + break; + case 6: + xprintf(" - Audio %02X\n", debug_temp); + chThdSleepMilliseconds(2); + break; + case 7: + xprintf("Frame %02X", debug_temp); + chThdSleepMilliseconds(2); + break; + case 8: + xprintf(" - Breath1 %02X\n", debug_temp); + chThdSleepMilliseconds(2); + break; + case 9: + xprintf("Breath2 %02X - ", debug_temp); + chThdSleepMilliseconds(2); + break; + case 10: + xprintf(" - Shut %02X\n", debug_temp); + chThdSleepMilliseconds(2); + break; + case 11: + xprintf("AGC %02X", debug_temp); + chThdSleepMilliseconds(2); + break; + case 12: + xprintf(" - ADC %02X\n", debug_temp); + chThdSleepMilliseconds(2); + break; } -#endif } } @@ -523,7 +518,7 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint //returns 2 bytes led control register address and byte to write //0 - bit off, 1 - bit on, 2 - toggle bit - uint8_t control_reg_addr, column_bit, column_byte, temp, blink_on; + uint8_t control_reg_addr, column_bit, column_byte, bit_temp, blink_on; //check for valid led address if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) { @@ -541,18 +536,28 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint //first byte is led control register address 0x00 //msg_led tens column is pin#, ones column is bit position in 8-bit mask control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte - xprintf("pre-reg_addr: %X\n", control_reg_addr); + xprintf("pre-reg_addr: %2X\n", control_reg_addr); chThdSleepMilliseconds(10); control_reg_addr += blink_on == 1 ? 0x12 : 0x00;//shift 12 bytes to blink register - xprintf("blink-reg_addr: %X\n", control_reg_addr); + xprintf("blink-reg_addr: %2X\n", control_reg_addr); + chThdSleepMilliseconds(10); + xprintf("page: %2X\n", page); chThdSleepMilliseconds(10); + + is31_read_register(page, 0x06, &bit_temp);//maintain status of leds on this byte + xprintf("reg 06: %2X\n", bit_temp); + is31_read_register(page, 0x17, &bit_temp);//maintain status of leds on this byte + xprintf("reg 17: %2X\n", bit_temp); + is31_read_register(page, 0x18, &bit_temp);//maintain status of leds on this byte + xprintf("reg 18: %2X\n", bit_temp); + is31_read_register(page, 0x19, &bit_temp);//maintain status of leds on this byte + xprintf("reg 19: %2X\n", bit_temp); + is31_read_register(page, control_reg_addr, &bit_temp);//maintain status of leds on this byte column_bit = 1<<(led_addr % 10 - 1); + column_byte = bit_temp; - is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte - column_byte = temp; - - xprintf("column_byte read: %X\n", column_byte); + xprintf("column_byte read: %2X\n", column_byte); chThdSleepMilliseconds(10); switch(action) { case 0: @@ -565,7 +570,7 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint column_byte ^= column_bit; break; } - xprintf("column_byte write: %X\n", column_byte); + xprintf("column_byte write: %2X\n", column_byte); chThdSleepMilliseconds(10); //return word to be written in register @@ -574,47 +579,59 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint } void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte) { - uint8_t led_control_word[2] = {0};//register address and led on/off mask + uint8_t led_control_word[2] = {0};//register address and on/off byte led_control_word[0] = (row - 1 ) * 0x02;// A-register is every other byte - led_control_word[1] = led_byte;// A-register is every other byte - is31_write_data(page, led_control_word, 0x13); + led_control_word[1] = led_byte; + is31_write_data(page, led_control_word, 0x02); } void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) { uint8_t i; uint8_t pin, col; - uint8_t led_control_register[0x13] = {0};//led control register start address + 0x12 bytes + uint8_t led_control_register[0x13] = {0};//control register start address + 0x12 bytes __builtin_memset(led_control_register,0,13); for(i=0;i