Update lock led processing and remove debug msgs
This commit is contained in:
		
							parent
							
								
									ac97870801
								
							
						
					
					
						commit
						9af272e4bb
					
				| @ -247,7 +247,6 @@ bool process_record_user (uint16_t keycode, keyrecord_t *record) { | |||||||
| 
 | 
 | ||||||
| // Runs just one time when the keyboard initializes.
 | // Runs just one time when the keyboard initializes.
 | ||||||
| void matrix_init_user(void) { | void matrix_init_user(void) { | ||||||
|     xprintf("init start"); |  | ||||||
| 
 | 
 | ||||||
|     led_controller_init(); |     led_controller_init(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -135,7 +135,6 @@ msg_t is31_read_register(uint8_t page, uint8_t reg, uint8_t *result) { | |||||||
|  * initialise the IS31 chip |  * initialise the IS31 chip | ||||||
|  * ======================== */ |  * ======================== */ | ||||||
| void is31_init(void) { | void is31_init(void) { | ||||||
|       xprintf("_is31_init\n"); |  | ||||||
|   // just to be sure that it's all zeroes
 |   // just to be sure that it's all zeroes
 | ||||||
|   __builtin_memset(full_page,0,0xB4+1); |   __builtin_memset(full_page,0,0xB4+1); | ||||||
|   // zero function page, all registers (assuming full_page is all zeroes)
 |   // zero function page, all registers (assuming full_page is all zeroes)
 | ||||||
| @ -200,41 +199,33 @@ static THD_FUNCTION(LEDthread, arg) { | |||||||
|     msg_args[1] = (msg >> 16) & 0XFF; |     msg_args[1] = (msg >> 16) & 0XFF; | ||||||
|     msg_args[2] = (msg >> 24) & 0xFF; |     msg_args[2] = (msg >> 24) & 0xFF; | ||||||
| 
 | 
 | ||||||
|       xprintf("msg_type: %d-%d-%d\n", msg_type, msg_args[0], msg_args[1]); |  | ||||||
| 
 | 
 | ||||||
|     switch (msg_type){ |     switch (msg_type){ | ||||||
|       case SET_FULL_ROW: |       case SET_FULL_ROW: | ||||||
|       xprintf("FULL ROW: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|       //write full byte to pin address, msg_args[1] = pin #, msg_args[0] = 8 bits to write
 |       //write full byte to pin address, msg_args[1] = pin #, msg_args[0] = 8 bits to write
 | ||||||
|       //writes only to currently displayed page
 |       //writes only to currently displayed page
 | ||||||
|         write_led_byte(page_status, msg_args[1], msg_args[0]); |         write_led_byte(page_status, msg_args[1], msg_args[0]); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|       case OFF_LED: |       case OFF_LED: | ||||||
|       xprintf("OFF: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|       //on/off/toggle single led, msg_args[0] = row/col of led, msg_args[1] = page
 |       //on/off/toggle single led, msg_args[0] = row/col of led, msg_args[1] = page
 | ||||||
|         set_led_bit(msg_args[1], control_register_word, msg_args[0], 0); |         set_led_bit(msg_args[1], control_register_word, msg_args[0], 0); | ||||||
|         break; |         break; | ||||||
|       case ON_LED: |       case ON_LED: | ||||||
|       xprintf("ON: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|         set_led_bit(msg_args[1], control_register_word, msg_args[0], 1); |         set_led_bit(msg_args[1], control_register_word, msg_args[0], 1); | ||||||
|         break; |         break; | ||||||
|       case TOGGLE_LED: |       case TOGGLE_LED: | ||||||
|       xprintf("TOGGLE: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|         set_led_bit(msg_args[1], control_register_word, msg_args[0], 2); |         set_led_bit(msg_args[1], control_register_word, msg_args[0], 2); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|       case BLINK_OFF_LED: |       case BLINK_OFF_LED: | ||||||
|       xprintf("B_on: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|       //on/off/toggle single led, msg_args[0] = row/col of led
 |       //on/off/toggle single led, msg_args[0] = row/col of led
 | ||||||
|         set_led_bit(msg_args[1], control_register_word, msg_args[0], 4); |         set_led_bit(msg_args[1], control_register_word, msg_args[0], 4); | ||||||
|         break; |         break; | ||||||
|       case BLINK_ON_LED: |       case BLINK_ON_LED: | ||||||
|       xprintf("B_off: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|         set_led_bit(msg_args[1], control_register_word, msg_args[0], 5); |         set_led_bit(msg_args[1], control_register_word, msg_args[0], 5); | ||||||
|         break; |         break; | ||||||
|       case BLINK_TOGGLE_LED: |       case BLINK_TOGGLE_LED: | ||||||
|       xprintf("B_togg: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|         set_led_bit(msg_args[1], control_register_word, msg_args[0], 6); |         set_led_bit(msg_args[1], control_register_word, msg_args[0], 6); | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
| @ -244,12 +235,10 @@ static THD_FUNCTION(LEDthread, arg) { | |||||||
|         chThdSleepMilliseconds(5); |         chThdSleepMilliseconds(5); | ||||||
|         is31_read_register(0, 0x00, &temp); |         is31_read_register(0, 0x00, &temp); | ||||||
|         is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); |         is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); | ||||||
|       xprintf("TOGGLE_ALL: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|       xprintf("temp: %d\n", temp); |  | ||||||
| 
 | 
 | ||||||
|         led_control_reg[0] = 0; |         led_control_reg[0] = 0; | ||||||
| 
 | 
 | ||||||
|         //if first leds are already on, toggle frame 0 off
 |         //toggle led mask based on current state (temp)
 | ||||||
|         if (temp==0 || page_status > 0) { |         if (temp==0 || page_status > 0) { | ||||||
|           __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12); |           __builtin_memcpy(led_control_reg+1, all_on_leds_mask, 0x12); | ||||||
|         } else { |         } else { | ||||||
| @ -262,13 +251,14 @@ static THD_FUNCTION(LEDthread, arg) { | |||||||
| 
 | 
 | ||||||
|           page_status=0; |           page_status=0; | ||||||
| 
 | 
 | ||||||
|           //maintain lock leds
 |           //maintain lock leds, reset to off and force recheck to blink of all leds toggled on
 | ||||||
|  |           numlock_status = 0; | ||||||
|  |           capslock_status = 0; | ||||||
|           led_set(host_keyboard_leds()); |           led_set(host_keyboard_leds()); | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|       case TOGGLE_BACKLIGHT: |       case TOGGLE_BACKLIGHT: | ||||||
|       xprintf("TOGGLE_BKLT: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|         //msg_args[0] = on/off
 |         //msg_args[0] = on/off
 | ||||||
| 
 | 
 | ||||||
|         //populate 9 byte rows to be written to each pin, first byte is register (pin) address
 |         //populate 9 byte rows to be written to each pin, first byte is register (pin) address
 | ||||||
| @ -287,12 +277,13 @@ static THD_FUNCTION(LEDthread, arg) { | |||||||
| 
 | 
 | ||||||
|       case DISPLAY_PAGE: |       case DISPLAY_PAGE: | ||||||
|       //msg_args[0] = page to toggle on
 |       //msg_args[0] = page to toggle on
 | ||||||
|       xprintf("DSPY_PG: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|         if (page_status != msg_args[0]) { |         if (page_status != msg_args[0]) { | ||||||
|           is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_args[0]); |           is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_args[0]); | ||||||
|           page_status = msg_args[0]; |           page_status = msg_args[0]; | ||||||
| 
 | 
 | ||||||
|           //maintain lock leds
 |           //maintain lock leds, reset to off and force recheck for new page
 | ||||||
|  |           numlock_status = 0; | ||||||
|  |           capslock_status = 0; | ||||||
|           led_set(host_keyboard_leds()); |           led_set(host_keyboard_leds()); | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
| @ -309,7 +300,6 @@ static THD_FUNCTION(LEDthread, arg) { | |||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|       case TOGGLE_NUM_LOCK: |       case TOGGLE_NUM_LOCK: | ||||||
|       xprintf("NMLK: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|       //msg_args[0] = 0 or 1, off/on
 |       //msg_args[0] = 0 or 1, off/on
 | ||||||
|         if (numlock_status != msg_args[0]) { |         if (numlock_status != msg_args[0]) { | ||||||
|           set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_args[0], page_status); |           set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_args[0], page_status); | ||||||
| @ -317,7 +307,6 @@ static THD_FUNCTION(LEDthread, arg) { | |||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|       case TOGGLE_CAPS_LOCK: |       case TOGGLE_CAPS_LOCK: | ||||||
|       xprintf("CPLK: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|       //msg_args[0] = 0 or 1, off/on
 |       //msg_args[0] = 0 or 1, off/on
 | ||||||
|         if (capslock_status != msg_args[0]) { |         if (capslock_status != msg_args[0]) { | ||||||
|           set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_args[0], page_status); |           set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_args[0], page_status); | ||||||
| @ -326,7 +315,6 @@ static THD_FUNCTION(LEDthread, arg) { | |||||||
|         break; |         break; | ||||||
| 
 | 
 | ||||||
|       case STEP_BRIGHTNESS: |       case STEP_BRIGHTNESS: | ||||||
|       xprintf("Step: %d-%d\n", msg_args[0], msg_args[1]); |  | ||||||
|       //led_args[0] = step up (1) or down (0)
 |       //led_args[0] = step up (1) or down (0)
 | ||||||
|         switch (msg_args[0]) { |         switch (msg_args[0]) { | ||||||
|           case 0: |           case 0: | ||||||
| @ -373,7 +361,6 @@ void set_led_bit (uint8_t page, uint8_t *led_control_word, uint8_t led_addr, uin | |||||||
|   if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) { |   if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) { | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|       xprintf("_set action-led: %x-%d\n", action, led_addr); |  | ||||||
| 
 | 
 | ||||||
|   blink_bit = action>>2;//check for blink bit
 |   blink_bit = action>>2;//check for blink bit
 | ||||||
|   action &= ~(1<<2); //strip blink bit
 |   action &= ~(1<<2); //strip blink bit
 | ||||||
| @ -381,17 +368,14 @@ void set_led_bit (uint8_t page, uint8_t *led_control_word, uint8_t led_addr, uin | |||||||
|   //led_addr tens column is pin#, ones column is bit position in 8-bit mask
 |   //led_addr tens column is pin#, ones column is bit position in 8-bit mask
 | ||||||
|   control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-matrix is every other byte
 |   control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-matrix is every other byte
 | ||||||
|   control_reg_addr += blink_bit == 1 ? 0x12 : 0x00;//if blink_bit, shift 12 bytes to blink register
 |   control_reg_addr += blink_bit == 1 ? 0x12 : 0x00;//if blink_bit, shift 12 bytes to blink register
 | ||||||
|       xprintf("_set control address: %x\n", control_reg_addr); |  | ||||||
| 
 | 
 | ||||||
|   is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON); |   is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON); | ||||||
|   chThdSleepMilliseconds(5); |   chThdSleepMilliseconds(5); | ||||||
|   is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte
 |   is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte
 | ||||||
|   is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); |   is31_write_register(IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF); | ||||||
|       xprintf("_set temp_byte_mask: %x\n", temp); |  | ||||||
| 
 | 
 | ||||||
|   column_bit = 1<<(led_addr % 10 - 1); |   column_bit = 1<<(led_addr % 10 - 1); | ||||||
|   column_byte = temp; |   column_byte = temp; | ||||||
|       xprintf("_set col_byte_mask: %x\n", column_byte); |  | ||||||
| 
 | 
 | ||||||
|   switch(action) { |   switch(action) { | ||||||
|     case 0: |     case 0: | ||||||
| @ -451,7 +435,6 @@ void set_lock_leds(uint8_t led_addr, uint8_t led_action, uint8_t page) { | |||||||
|       led_action |= (1<<2); //set blink bit
 |       led_action |= (1<<2); //set blink bit
 | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|       xprintf("_lock action: %d\n", led_action); |  | ||||||
| 
 | 
 | ||||||
|   set_led_bit(page,led_control_word,led_addr,led_action); |   set_led_bit(page,led_control_word,led_addr,led_action); | ||||||
| } | } | ||||||
| @ -462,7 +445,6 @@ void set_lock_leds(uint8_t led_addr, uint8_t led_action, uint8_t page) { | |||||||
| void led_controller_init(void) { | void led_controller_init(void) { | ||||||
|   uint8_t i; |   uint8_t i; | ||||||
| 
 | 
 | ||||||
|       xprintf("led_init\n"); |  | ||||||
|   /* initialise I2C */ |   /* initialise I2C */ | ||||||
|   /* I2C pins */ |   /* I2C pins */ | ||||||
|   palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL
 |   palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATIVE_2); // PTB0/I2C0/SCL
 | ||||||
|  | |||||||
| @ -75,7 +75,8 @@ void led_controller_init(void); | |||||||
| // D2:D0 extinguish time (3.5ms*2^i)
 | // D2:D0 extinguish time (3.5ms*2^i)
 | ||||||
| 
 | 
 | ||||||
| #define IS31_REG_SHUTDOWN 0x0A | #define IS31_REG_SHUTDOWN 0x0A | ||||||
| #define IS31_REG_SHUTDOWN_ON 0x1 | #define IS31_REG_SHUTDOWN_OFF 0x1 | ||||||
|  | #define IS31_REG_SHUTDOWN_ON 0x0 | ||||||
| 
 | 
 | ||||||
| #define IS31_REG_AGCCTRL 0x0B | #define IS31_REG_AGCCTRL 0x0B | ||||||
| #define IS31_REG_ADCRATE 0x0C | #define IS31_REG_ADCRATE 0x0C | ||||||
|  | |||||||
| @ -56,7 +56,7 @@ OPT_DEFS = -DCORTEX_VTOR_INIT=0x00001000 | |||||||
| # Build Options
 | # Build Options
 | ||||||
| #   comment out to disable the options.
 | #   comment out to disable the options.
 | ||||||
| #
 | #
 | ||||||
| BOOTMAGIC_ENABLE ?= yes	# Virtual DIP switch configuration | BOOTMAGIC_ENABLE ?= no	# Virtual DIP switch configuration | ||||||
| ## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
 | ## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
 | ||||||
| MOUSEKEY_ENABLE ?= yes	# Mouse keys | MOUSEKEY_ENABLE ?= yes	# Mouse keys | ||||||
| EXTRAKEY_ENABLE ?= yes	# Audio control and System control | EXTRAKEY_ENABLE ?= yes	# Audio control and System control | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user