diff options
author | jpetermans <tibcmhhm@gmail.com> | 2017-05-08 11:57:40 -0700 |
---|---|---|
committer | jpetermans <tibcmhhm@gmail.com> | 2017-05-08 11:57:40 -0700 |
commit | 52f671c23eaeff9547e2a02154f0a056278b113c (patch) | |
tree | 7a80cfe3377eb23da405ff9295ac3694deb8fc49 | |
parent | b27fb216efaa095d19b0175b9f64f96ff5e3544a (diff) |
small code cleanup
-rw-r--r-- | keyboards/infinity60/MEMO.txt | 385 | ||||
-rw-r--r-- | keyboards/infinity60/led_controller.c | 385 | ||||
-rw-r--r-- | keyboards/infinity60/led_controller.h | 16 |
3 files changed, 210 insertions, 576 deletions
diff --git a/keyboards/infinity60/MEMO.txt b/keyboards/infinity60/MEMO.txt deleted file mode 100644 index e2886aa002..0000000000 --- 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 --------- - # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES) - MCU_FAMILY = KINETIS - MCU_SERIES = KL2x - - # - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/ - # or <this_dir>/ld/ - MCU_LDSCRIPT = MKL26Z64 - - # - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/ - MCU_STARTUP = kl2x - - # Board: it should exist either in <chibios>/os/hal/boards/ - # or <this_dir>/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 59ca833b65..c162e9a8f0 100644 --- a/keyboards/infinity60/led_controller.c +++ b/keyboards/infinity60/led_controller.c @@ -72,8 +72,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #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<<USB_LED_NUM_LOCK)) { - set_lock_leds(USB_LED_NUM_LOCK, 1); - } - if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { - set_lock_leds(USB_LED_CAPS_LOCK, 1); - } + page_status=0; - page_status=0; + //maintain lock leds + led_set(host_keyboard_leds()); + } break; case TOGGLE_BACKLIGHT: @@ -306,81 +306,75 @@ page_status = 0; //start frame 0 (all off/on) case DISPLAY_PAGE://show single layer indicator or full map of layer //msg_led = page to toggle on - xprintf("DISPLAY_PAGE"); + xprintf("DISPLAY_PAGE\n"); chThdSleepMilliseconds(10); if (page_status != msg_led) { xprintf(" - new page\n"); chThdSleepMilliseconds(10); is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led); + page_status = msg_led; + + //maintain lock leds + led_set(host_keyboard_leds()); } - page_status = msg_led; break; case RESET_PAGE: + //led_msg = page to reset xprintf("RESET_PAGE\n"); - chThdSleepMilliseconds(10); - //led_msg = page to reset + chThdSleepMilliseconds(10); led_control_reg[0] = 0; __builtin_memset(led_control_reg+1, 0, 0x12); is31_write_data(msg_led, led_control_reg, 0x13); - - //maintain lock leds - if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { - set_lock_leds(USB_LED_NUM_LOCK, 1); - } - if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { - set_lock_leds(USB_LED_CAPS_LOCK, 1); - } break; case TOGGLE_NUM_LOCK: //msg_led = 0 or 1, off/on xprintf("NUMLOCK: %d\n", msg_led); chThdSleepMilliseconds(10); - set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_led); + set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_led, page_status); break; case TOGGLE_CAPS_LOCK: xprintf("CAPSLOCK: %d\n", msg_led); chThdSleepMilliseconds(10); //msg_led = 0 or 1, off/on - set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_led); + set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_led, page_status); break; //TODO: MODE_BREATH - case MODE_BREATH: - break; + case STEP_BRIGHTNESS: xprintf("STEP_BACKLIGHT\n"); chThdSleepMilliseconds(10); //led_msg = step pwm up or down - switch (msg_led) { - case 0: - if (pwm_step_status == 0) { - pwm_step_status = 4; - } else { - pwm_step_status--; - } - break; - - case 1: - if (pwm_step_status == 4) { - pwm_step_status = 0; - } else { - pwm_step_status++; - } - break; - } + switch (msg_led) { + case 0: + if (pwm_step_status == 0) { + pwm_step_status = 4; + } else { + pwm_step_status--; + } + break; + + case 1: + if (pwm_step_status == 4) { + pwm_step_status = 0; + } else { + pwm_step_status++; + } + break; + } - //populate 8 byte rows to write on each pin - //first byte is register address, every 0x10 9 bytes are A-register pwm pins - __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); + //populate 8 byte rows to write on each pin + //first byte is register address, every 0x10 9 bytes are A-register pwm pins + __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); - for(i=0; i<8; i++) { - pwm_register_array[0] = 0x24 + (i * 0x10); - is31_write_data(0,pwm_register_array,9); - } - break; + for(i=0; i<8; i++) { + pwm_register_array[0] = 0x24 + (i * 0x10); + is31_write_data(0,pwm_register_array,9); + } + break; /* case LED_MSG_SLEEP_LED_ON: // save current settings @@ -415,103 +409,104 @@ page_status = 0; //start frame 0 (all off/on) xprintf("--------------------\n"); chThdSleepMilliseconds(10); } -#if DEBUG_ENABLED - uint8_t j; - uint8_t pages[3]={0x00, 0x07}; - //debugging code - print full led/blink/pwm registers on each frame - xprintf("----layer state----: %X\n", layer_state); - for(i=0;i<2;i++) { - xprintf("page: %d\n", pages[i]); - chThdSleepMilliseconds(2); - for(j=0;j<0x24;j++){ - if(j > 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"); +/* ============================== + * 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); + } - //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; - } + 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); - column_bit = 1<<(led_addr % 10 - 1); - is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte - column_byte = temp; + 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; - 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<led_count;i++){ - pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1;// 1 byte shift for led register 0x00 address + // 1 byte shift for led register 0x00 address + pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1; col = user_led_array[i] % 10 - 1; - led_control_register[pin] |= 1<<(col); } is31_write_data(page, led_control_register, 0x13); } -void set_lock_leds(uint8_t led_addr, uint8_t led_action) { - uint8_t page, temp; +void set_lock_leds(uint8_t led_addr, uint8_t led_action, uint8_t page) { + uint8_t lock_temp; uint8_t led_control_word[2] = {0}; + xprintf("---set lock---\n"); + chThdSleepMilliseconds(10); + //blink if all leds are on - //is31_read_register(0, 0x00, &temp); - //if (temp != 0x00) { - // set_led_bit(0,led_control_word,led_addr,(led_action | (1<<2))); //set blink bit - //} else { - // set_led_bit(0,led_control_word,led_addr,led_action); - //} - //is31_write_data(0, led_control_word, 0x02); - - for(page=1; page<8; page++) { - set_led_bit(page,led_control_word,led_addr,led_action); - is31_write_data(page, led_control_word, 0x02); + if (page == 0) { + is31_read_register(0, 0x00, &lock_temp); + xprintf("AllOnReg: %2X\n", lock_temp); + chThdSleepMilliseconds(10); + if (lock_temp == 0xFF) { + xprintf("AllOntrue\n"); + chThdSleepMilliseconds(10); + led_action |= (1<<2); //set blink bit + } else { + xprintf("AllOnfalse\n"); + chThdSleepMilliseconds(10); + } } + + set_led_bit(page,led_control_word,led_addr,led_action); + + xprintf("led_word: %2X", led_control_word[0]); + xprintf("%X\n", led_control_word[1]); + chThdSleepMilliseconds(10); + + is31_write_data(page, led_control_word, 0x02); } /* ===================== @@ -639,11 +656,11 @@ void led_controller_init(void) { /* initialise IS31 chip */ is31_init(); - //set Display Option Register so all pwm intensity is controlled from Frame 0 + //set Display Option Register so all pwm intensity is controlled from page 0 //enable blink and set blink period to 0.27s x rate - is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME + S31_REG_DISPLAYOPT_BLINK_ENABLE + 5); + is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME + IS31_REG_DISPLAYOPT_BLINK_ENABLE + 4); - /* set full pwm on Frame 1 */ + /* set full pwm on page 1 */ pwm_register_array[0] = 0; __builtin_memset(pwm_register_array+1, 0xFF, 8); for(i=0; i<8; i++) { diff --git a/keyboards/infinity60/led_controller.h b/keyboards/infinity60/led_controller.h index 455f060500..7bdef7ae63 100644 --- a/keyboards/infinity60/led_controller.h +++ b/keyboards/infinity60/led_controller.h @@ -31,6 +31,7 @@ msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result); * ============================*/ void led_controller_init(void); +void print_debug (uint8_t page); #define CAPS_LOCK_LED_ADDRESS 46 //pin matrix location #define NUM_LOCK_LED_ADDRESS 85 @@ -58,7 +59,7 @@ void led_controller_init(void); #define IS31_REG_DISPLAYOPT 0x05 #define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames -#define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x8 +#define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x08 // D2:D0 bits blink period time (*0.27s) #define IS31_REG_AUDIOSYNC 0x06 @@ -86,32 +87,33 @@ void led_controller_init(void); #define IS31_TIMEOUT 10000 // needs to be long enough to write a whole page /* ======================================== - * LED Thread related functions/definitions + * LED Thread related items * ========================================*/ extern mailbox_t led_mailbox; void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action); -void set_lock_leds (uint8_t led_addr, uint8_t led_action); +void set_lock_leds (uint8_t led_addr, uint8_t led_action, uint8_t page); void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte); void write_led_page (uint8_t page, uint8_t *led_array, uint8_t led_count); // constants for signaling the LED controller thread enum led_msg_t { KEY_LIGHT, - BLINK_OFF_LED, - BLINK_ON_LED, - BLINK_TOGGLE_LED, + SET_FULL_ROW, OFF_LED, ON_LED, TOGGLE_LED, + BLINK_OFF_LED, + BLINK_ON_LED, + BLINK_TOGGLE_LED, TOGGLE_ALL, TOGGLE_BACKLIGHT, DISPLAY_PAGE, RESET_PAGE, TOGGLE_NUM_LOCK, TOGGLE_CAPS_LOCK, - MODE_BREATH, + TOGGLE_BREATH, STEP_BRIGHTNESS }; |