aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjpetermans <tibcmhhm@gmail.com>2017-05-08 11:57:40 -0700
committerjpetermans <tibcmhhm@gmail.com>2017-05-08 11:57:40 -0700
commit52f671c23eaeff9547e2a02154f0a056278b113c (patch)
tree7a80cfe3377eb23da405ff9295ac3694deb8fc49
parentb27fb216efaa095d19b0175b9f64f96ff5e3544a (diff)
downloadqmk_firmware-52f671c23eaeff9547e2a02154f0a056278b113c.tar.gz
qmk_firmware-52f671c23eaeff9547e2a02154f0a056278b113c.zip
small code cleanup
-rw-r--r--keyboards/infinity60/MEMO.txt385
-rw-r--r--keyboards/infinity60/led_controller.c385
-rw-r--r--keyboards/infinity60/led_controller.h16
3 files changed, 210 insertions, 576 deletions
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 @@
1flabbergast's TMK/ChibiOS port
2==============================
32015/10/16
4
5
6Build
7-----
8$ git clone -b chibios https://github.com/flabbergast/tmk_keyboard.git
9
10$ cd tmk_keyboard
11$ git submodule add -f -b kinetis https://github.com/flabbergast/ChibiOS.git tmk_core/tool/chibios/chibios
12or
13$ cd tmk_keyboard/tmk_core/tool/chibios
14$ git clone -b kinetis https://github.com/flabbergast/ChibiOS.git tmk_core/tool/chibios/chibios
15
16$ cd tmk_keyboard/keyboard/infinity_chibios
17$ make
18
19
20
21
22Chibios Configuration
23---------------------
24halconf.h: for HAL configuration
25 placed in project directory
26 read in chibios/os/hal/hal.mk
27 included in chibios/os/hal/include/hal.h
28mcuconf.h: for MCU configuration
29 placed in project directory
30 included in halconf.h
31
32
33Chibios Term
34------------
35PAL = Port Abstraction Layer
36 palWritePad
37 palReadPad
38 palSetPad
39 chibios/os/hal/include/pal.h
40
41LLD = Low Level Driver
42
43
44Makefile
45--------
46 # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
47 MCU_FAMILY = KINETIS
48 MCU_SERIES = KL2x
49
50 # - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
51 # or <this_dir>/ld/
52 MCU_LDSCRIPT = MKL26Z64
53
54 # - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
55 MCU_STARTUP = kl2x
56
57 # Board: it should exist either in <chibios>/os/hal/boards/
58 # or <this_dir>/boards
59 BOARD = PJRC_TEENSY_LC
60
61 MCU = cortex-m0
62
63 # ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
64 ARMV = 6
65
66
67halconf.h
68---------
69
70
71mcuconf.h
72---------
73
74
75chconf.h
76--------
77
78
79ld script
80---------
81--- ../../tmk_core/tool/chibios/chibios/os/common/ports/ARMCMx/compilers/GCC/ld/MKL26Z64.ld 2015-10-15 09:08:58.732904304 +0900
82+++ ld/MKL26Z64.ld 2015-10-15 08:48:06.430215496 +0900
83@@ -27,7 +27,8 @@
84 {
85 flash0 : org = 0x00000000, len = 0xc0
86 flashcfg : org = 0x00000400, len = 0x10
87- flash : org = 0x00000410, len = 64k - 0x410
88+ flash : org = 0x00000410, len = 62k - 0x410
89+ eeprom_emu : org = 0x0000F800, len = 2k
90 ram : org = 0x1FFFF800, len = 8k
91 }
92
93@@ -35,6 +36,10 @@
94 __ram_size__ = LENGTH(ram);
95 __ram_end__ = __ram_start__ + __ram_size__;
96
97+__eeprom_workarea_start__ = ORIGIN(eeprom_emu);
98+__eeprom_workarea_size__ = LENGTH(eeprom_emu);
99+__eeprom_workarea_end__ = __eeprom_workarea_start__ + __eeprom_workarea_size__;
100+
101 SECTIONS
102 {
103 . = 0;
104
105
106
107Configuration/Startup for Infinity 60%
108--------------------------------------
109Configuration:
110
111
112Clock:
113Inifinity
114 FEI(FLL Engaged Internal) mode with core clock:48MHz, bus clock:48MHz, flash clock:24MHz
115 Clock dividor:
116 SIM_CLKDIV1[OUTDIV1] = 0 divide-by-1 for core clock
117 SIM_CLKDIV1[OUTDIV2] = 0 divide-by-1 for bus clock
118 SIM_CLKDIV1[OUTDIV4] = 1 divide-by-2 for flash clock
119 Internal reference clock:
120 MCG_C1[IREFS] = 1 Internal Reference Select for clock source for FLL
121 MCG_C1[IRCLKEN] = 1 Internal Reference Clock Enable
122 FLL multipilication:
123 MCG_C4[DMX32] = 1
124 MCG_C4[DRST_DRS] = 01 FLL factor 1464 * 32.768kHz = 48MHz
125
126chibios/os/hal/ports/KINETIS/K20x/hal_lld.c
127 k20x_clock_init(): called in __early_init() defined in board.c
128 disable watchdog and configure clock
129
130 configurable macros:
131 KINETIS_NO_INIT: whether init or not
132 KINETIS_MCG_MODE: clock mode
133 KINETIS_MCG_MODE_FEI
134 KINETIS_MCG_MODE_PEE
135 hal/ports/KINETIS/K20x/hal_lld.h
136
137
138chibios/os/hal/boards/FREESCALE_FREEDOM_K20D50M/board.h
139 PALConfig pal_default_config
140 boardInit()
141 __early_init()
142 macro definitions for board infos, freq and mcu type
143
144chibios/os/hal/boards/FREESCALE_FREEDOM_K20D50M/board.c
145
146USB
147
148
149Startup
150-------
151 common/ports/ARMCMx/GCC/crt0_v[67]m.s
152 Reset_Handler: startup code
153 common/ports/ARMCMx/GCC/crt1.c
154 __core_init(): weak
155 __early_init(): weak
156 __late_init(): weak
157 __default_exit(): weak
158 called from Reset_Handler of crt0
159 common/ports/ARMCMx/GCC/vector.c
160 common/ports/ARMCMx/GCC/ld/*.ld
161
162chibios/os/common/ports/ARMCMx/compilers/GCC/
163├── crt0_v6m.s
164├── crt0_v7m.s
165├── crt1.c
166├── ld
167│   ├── MK20DX128BLDR3.ld
168│   ├── MK20DX128BLDR4.ld
169│   ├── MK20DX128.ld
170│   ├── MK20DX256.ld
171│   ├── MKL25Z128.ld
172│   ├── MKL26Z128.ld
173│   ├── MKL26Z64.ld
174│   └── STM32L476xG.ld
175├── mk
176│   ├── startup_k20x5.mk
177│   ├── startup_k20x7.mk
178│   ├── startup_k20x.mk
179│   ├── startup_kl2x.mk
180│   └── startup_stm32l4xx.mk
181├── rules.ld
182├── rules.mk
183└── vectors.c
184
185chibios/os/hal/
186├── boards
187│   ├── FREESCALE_FREEDOM_K20D50M
188│   │   ├── board.c
189│   │   ├── board.h
190│   │   └── board.mk
191│   ├── MCHCK_K20
192│   │   ├── board.c
193│   │   ├── board.h
194│   │   └── board.mk
195│   ├── PJRC_TEENSY_3
196│   │   ├── board.c
197│   │   ├── board.h
198│   │   └── board.mk
199│   ├── PJRC_TEENSY_3_1
200│   │   ├── board.c
201│   │   ├── board.h
202│   │   └── board.mk
203│   ├── PJRC_TEENSY_LC
204│   │   ├── board.c
205│   │   ├── board.h
206│   │   └── board.mk
207│   ├── readme.txt
208│   ├── simulator
209│   │   ├── board.c
210│   │   ├── board.h
211│   │   └── board.mk
212│   ├── ST_NUCLEO_F030R8
213│   │   ├── board.c
214│   │   ├── board.h
215│   │   ├── board.mk
216│   │   └── cfg
217│   │   └── board.chcfg
218├── hal.mk
219├── include
220│   ├── adc.h
221│   ├── can.h
222│   ├── dac.h
223│   ├── ext.h
224│   ├── gpt.h
225│   ├── hal_channels.h
226│   ├── hal_files.h
227│   ├── hal.h
228│   ├── hal_ioblock.h
229│   ├── hal_mmcsd.h
230│   ├── hal_queues.h
231│   ├── hal_streams.h
232│   ├── i2c.h
233│   ├── i2s.h
234│   ├── icu.h
235│   ├── mac.h
236│   ├── mii.h
237│   ├── mmc_spi.h
238│   ├── pal.h
239│   ├── pwm.h
240│   ├── rtc.h
241│   ├── sdc.h
242│   ├── serial.h
243│   ├── serial_usb.h
244│   ├── spi.h
245│   ├── st.h
246│   ├── uart.h
247│   └── usb.h
248├── lib
249│   └── streams
250│   ├── chprintf.c
251│   ├── chprintf.h
252│   ├── memstreams.c
253│   ├── memstreams.h
254│   ├── nullstreams.c
255│   └── nullstreams.h
256├── osal
257│   ├── nil
258│   │   ├── osal.c
259│   │   ├── osal.h
260│   │   └── osal.mk
261│   ├── os-less
262│   │   └── ARMCMx
263│   │   ├── osal.c
264│   │   ├── osal.h
265│   │   └── osal.mk
266│   └── rt
267│   ├── osal.c
268│   ├── osal.h
269│   └── osal.mk
270├── ports
271│   ├── AVR
272│   ├── common
273│   │   └── ARMCMx
274│   │   ├── mpu.h
275│   │   ├── nvic.c
276│   │   └── nvic.h
277│   ├── KINETIS
278│   │   ├── K20x
279│   │   │   ├── hal_lld.c
280│   │   │   ├── hal_lld.h
281│   │   │   ├── kinetis_registry.h
282│   │   │   ├── platform.dox
283│   │   │   ├── platform.mk
284│   │   │   ├── pwm_lld.c
285│   │   │   ├── pwm_lld.h
286│   │   │   ├── spi_lld.c
287│   │   │   └── spi_lld.h
288│   │   ├── KL2x
289│   │   │   ├── hal_lld.c
290│   │   │   ├── hal_lld.h
291│   │   │   ├── kinetis_registry.h
292│   │   │   ├── platform.mk
293│   │   │   ├── pwm_lld.c
294│   │   │   └── pwm_lld.h
295│   │   ├── LLD
296│   │   │   ├── adc_lld.c
297│   │   │   ├── adc_lld.h
298│   │   │   ├── ext_lld.c
299│   │   │   ├── ext_lld.h
300│   │   │   ├── gpt_lld.c
301│   │   │   ├── gpt_lld.h
302│   │   │   ├── i2c_lld.c
303│   │   │   ├── i2c_lld.h
304│   │   │   ├── pal_lld.c
305│   │   │   ├── pal_lld.h
306│   │   │   ├── serial_lld.c
307│   │   │   ├── serial_lld.h
308│   │   │   ├── st_lld.c
309│   │   │   ├── st_lld.h
310│   │   │   ├── usb_lld.c
311│   │   │   └── usb_lld.h
312│   │   └── README.md
313│   ├── LPC
314│   ├── simulator
315│   └── STM32
316├── src
317│   ├── adc.c
318│   ├── can.c
319│   ├── dac.c
320│   ├── ext.c
321│   ├── gpt.c
322│   ├── hal.c
323│   ├── hal_mmcsd.c
324│   ├── hal_queues.c
325│   ├── i2c.c
326│   ├── i2s.c
327│   ├── icu.c
328│   ├── mac.c
329│   ├── mmc_spi.c
330│   ├── pal.c
331│   ├── pwm.c
332│   ├── rtc.c
333│   ├── sdc.c
334│   ├── serial.c
335│   ├── serial_usb.c
336│   ├── spi.c
337│   ├── st.c
338│   ├── uart.c
339│   └── usb.c
340└── templates
341 ├── adc_lld.c
342 ├── adc_lld.h
343 ├── can_lld.c
344 ├── can_lld.h
345 ├── dac_lld.c
346 ├── dac_lld.h
347 ├── ext_lld.c
348 ├── ext_lld.h
349 ├── gpt_lld.c
350 ├── gpt_lld.h
351 ├── halconf.h
352 ├── hal_lld.c
353 ├── hal_lld.h
354 ├── i2c_lld.c
355 ├── i2c_lld.h
356 ├── i2s_lld.c
357 ├── i2s_lld.h
358 ├── icu_lld.c
359 ├── icu_lld.h
360 ├── mac_lld.c
361 ├── mac_lld.h
362 ├── mcuconf.h
363 ├── osal
364 │   ├── osal.c
365 │   ├── osal.h
366 │   └── osal.mk
367 ├── pal_lld.c
368 ├── pal_lld.h
369 ├── platform.mk
370 ├── pwm_lld.c
371 ├── pwm_lld.h
372 ├── rtc_lld.c
373 ├── rtc_lld.h
374 ├── sdc_lld.c
375 ├── sdc_lld.h
376 ├── serial_lld.c
377 ├── serial_lld.h
378 ├── spi_lld.c
379 ├── spi_lld.h
380 ├── st_lld.c
381 ├── st_lld.h
382 ├── uart_lld.c
383 ├── uart_lld.h
384 ├── usb_lld.c
385 └── 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 <http://www.gnu.org/licenses/>.
72#define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS 72#define BREATHE_LED_ADDRESS CAPS_LOCK_LED_ADDRESS
73#endif 73#endif
74 74
75#define DEBUG_ENABLED 1
76
77/* ================= 75/* =================
78 * ChibiOS I2C setup 76 * ChibiOS I2C setup
79 * ================= */ 77 * ================= */
@@ -145,7 +143,6 @@ void is31_init(void) {
145 __builtin_memset(full_page,0,0xB4+1); 143 __builtin_memset(full_page,0,0xB4+1);
146 // zero function page, all registers (assuming full_page is all zeroes) 144 // zero function page, all registers (assuming full_page is all zeroes)
147 is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1); 145 is31_write_data(IS31_FUNCTIONREG, full_page, 0xD + 1);
148 // disable hardware shutdown
149 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL); 146 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL);
150 palSetPad(GPIOB, 16); 147 palSetPad(GPIOB, 16);
151 chThdSleepMilliseconds(10); 148 chThdSleepMilliseconds(10);
@@ -182,7 +179,7 @@ static THD_FUNCTION(LEDthread, arg) {
182 uint8_t pwm_step_status, page_status; 179 uint8_t pwm_step_status, page_status;
183 180
184 //mailbox variables 181 //mailbox variables
185 uint8_t temp, msg_type, msg_led; 182 uint8_t temp, msg_type, msg_pin, msg_col, msg_led;
186 msg_t msg; 183 msg_t msg;
187 184
188/* //control register variables 185/* //control register variables
@@ -199,14 +196,17 @@ page_status = 0; //start frame 0 (all off/on)
199 // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't 196 // (messages are queued (up to LED_MAILBOX_NUM_MSGS) if they can't
200 // be processed right away) 197 // be processed right away)
201 chMBFetch(&led_mailbox, &msg, TIME_INFINITE); 198 chMBFetch(&led_mailbox, &msg, TIME_INFINITE);
202 msg_type = (msg >> 8) & 0xFF; //first byte is msg type 199 msg_col = (msg >> 24) & 0xFF;//if needed
203 msg_led = (msg) & 0xFF; //second byte is action information 200 msg_pin = (msg >> 16) & 0XFF;//if needed (SET_FULL_ROW)
201 msg_type = (msg >> 8) & 0xFF; //second byte is msg type
202 msg_led = (msg) & 0xFF; //first byte is action information
204 203
205 xprintf("--------------------\n"); 204 xprintf("--------------------\n");
206 chThdSleepMilliseconds(10);
207 xprintf("mailbox fetch\nmsg: %X\n", msg); 205 xprintf("mailbox fetch\nmsg: %X\n", msg);
208 chThdSleepMilliseconds(10); 206 chThdSleepMilliseconds(20);
209 xprintf("type: %X - led: %X\n", msg_type, msg_led); 207 xprintf("type: %X - pin: %X\n", msg_type, msg_pin);
208 chThdSleepMilliseconds(20);
209 xprintf("col: %X - led: %X\n", msg_col, msg_led);
210 chThdSleepMilliseconds(10); 210 chThdSleepMilliseconds(10);
211 211
212 switch (msg_type){ 212 switch (msg_type){
@@ -214,8 +214,12 @@ page_status = 0; //start frame 0 (all off/on)
214 //TODO: lighting key led on keypress 214 //TODO: lighting key led on keypress
215 break; 215 break;
216 216
217 //TODO: BLINK_ON/OFF_LED 217 case SET_FULL_ROW:
218 break; 218 //write full byte to pin address, msg_pin = pin #, msg_led = byte to write
219 //writes only to current page
220 xprintf("SET_FULL_ROW\n");
221 write_led_byte(page_status,msg_pin,msg_led);
222 break;
219 223
220 case OFF_LED: 224 case OFF_LED:
221 //on/off/toggle single led, msg_led = row/col of led 225 //on/off/toggle single led, msg_led = row/col of led
@@ -255,6 +259,7 @@ page_status = 0; //start frame 0 (all off/on)
255 chThdSleepMilliseconds(10); 259 chThdSleepMilliseconds(10);
256 set_led_bit(7, control_register_word, msg_led, 6); 260 set_led_bit(7, control_register_word, msg_led, 6);
257 is31_write_data (7, control_register_word, 0x02); 261 is31_write_data (7, control_register_word, 0x02);
262 break;
258 263
259 case TOGGLE_ALL: 264 case TOGGLE_ALL:
260 xprintf("TOGGLE_ALL: %d\n", msg_led); 265 xprintf("TOGGLE_ALL: %d\n", msg_led);
@@ -272,17 +277,12 @@ page_status = 0; //start frame 0 (all off/on)
272 277
273 if (page_status > 0) { 278 if (page_status > 0) {
274 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0); 279 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, 0);
275 }
276 280
277 //maintain lock leds 281 page_status=0;
278 if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) {
279 set_lock_leds(USB_LED_NUM_LOCK, 1);
280 }
281 if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) {
282 set_lock_leds(USB_LED_CAPS_LOCK, 1);
283 }
284 282
285 page_status=0; 283 //maintain lock leds
284 led_set(host_keyboard_leds());
285 }
286 break; 286 break;
287 287
288 case TOGGLE_BACKLIGHT: 288 case TOGGLE_BACKLIGHT:
@@ -306,81 +306,75 @@ page_status = 0; //start frame 0 (all off/on)
306 306
307 case DISPLAY_PAGE://show single layer indicator or full map of layer 307 case DISPLAY_PAGE://show single layer indicator or full map of layer
308 //msg_led = page to toggle on 308 //msg_led = page to toggle on
309 xprintf("DISPLAY_PAGE"); 309 xprintf("DISPLAY_PAGE\n");
310 chThdSleepMilliseconds(10); 310 chThdSleepMilliseconds(10);
311 if (page_status != msg_led) { 311 if (page_status != msg_led) {
312 xprintf(" - new page\n"); 312 xprintf(" - new page\n");
313 chThdSleepMilliseconds(10); 313 chThdSleepMilliseconds(10);
314 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led); 314 is31_write_register(IS31_FUNCTIONREG, IS31_REG_PICTDISP, msg_led);
315 page_status = msg_led;
316
317 //maintain lock leds
318 led_set(host_keyboard_leds());
315 } 319 }
316 page_status = msg_led;
317 break; 320 break;
318 321
319 case RESET_PAGE: 322 case RESET_PAGE:
323 //led_msg = page to reset
320 xprintf("RESET_PAGE\n"); 324 xprintf("RESET_PAGE\n");
321 chThdSleepMilliseconds(10); 325 chThdSleepMilliseconds(10);
322 //led_msg = page to reset
323 led_control_reg[0] = 0; 326 led_control_reg[0] = 0;
324 __builtin_memset(led_control_reg+1, 0, 0x12); 327 __builtin_memset(led_control_reg+1, 0, 0x12);
325 is31_write_data(msg_led, led_control_reg, 0x13); 328 is31_write_data(msg_led, led_control_reg, 0x13);
326
327 //maintain lock leds
328 if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) {
329 set_lock_leds(USB_LED_NUM_LOCK, 1);
330 }
331 if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) {
332 set_lock_leds(USB_LED_CAPS_LOCK, 1);
333 }
334 break; 329 break;
335 330
336 case TOGGLE_NUM_LOCK: 331 case TOGGLE_NUM_LOCK:
337 //msg_led = 0 or 1, off/on 332 //msg_led = 0 or 1, off/on
338 xprintf("NUMLOCK: %d\n", msg_led); 333 xprintf("NUMLOCK: %d\n", msg_led);
339 chThdSleepMilliseconds(10); 334 chThdSleepMilliseconds(10);
340 set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_led); 335 set_lock_leds(NUM_LOCK_LED_ADDRESS, msg_led, page_status);
341 break; 336 break;
342 337
343 case TOGGLE_CAPS_LOCK: 338 case TOGGLE_CAPS_LOCK:
344 xprintf("CAPSLOCK: %d\n", msg_led); 339 xprintf("CAPSLOCK: %d\n", msg_led);
345 chThdSleepMilliseconds(10); 340 chThdSleepMilliseconds(10);
346 //msg_led = 0 or 1, off/on 341 //msg_led = 0 or 1, off/on
347 set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_led); 342 set_lock_leds(CAPS_LOCK_LED_ADDRESS, msg_led, page_status);
348 break; 343 break;
349 344
350 //TODO: MODE_BREATH 345 //TODO: MODE_BREATH
351 case MODE_BREATH: 346
352 break;
353 case STEP_BRIGHTNESS: 347 case STEP_BRIGHTNESS:
354 xprintf("STEP_BACKLIGHT\n"); 348 xprintf("STEP_BACKLIGHT\n");
355 chThdSleepMilliseconds(10); 349 chThdSleepMilliseconds(10);
356 //led_msg = step pwm up or down 350 //led_msg = step pwm up or down
357 switch (msg_led) { 351 switch (msg_led) {
358 case 0: 352 case 0:
359 if (pwm_step_status == 0) { 353 if (pwm_step_status == 0) {
360 pwm_step_status = 4; 354 pwm_step_status = 4;
361 } else { 355 } else {
362 pwm_step_status--; 356 pwm_step_status--;
363 } 357 }
364 break; 358 break;
365 359
366 case 1: 360 case 1:
367 if (pwm_step_status == 4) { 361 if (pwm_step_status == 4) {
368 pwm_step_status = 0; 362 pwm_step_status = 0;
369 } else { 363 } else {
370 pwm_step_status++; 364 pwm_step_status++;
371 } 365 }
372 break; 366 break;
373 } 367 }
374 368
375 //populate 8 byte rows to write on each pin 369 //populate 8 byte rows to write on each pin
376 //first byte is register address, every 0x10 9 bytes are A-register pwm pins 370 //first byte is register address, every 0x10 9 bytes are A-register pwm pins
377 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8); 371 __builtin_memset(pwm_register_array+1, pwm_levels[pwm_step_status], 8);
378 372
379 for(i=0; i<8; i++) { 373 for(i=0; i<8; i++) {
380 pwm_register_array[0] = 0x24 + (i * 0x10); 374 pwm_register_array[0] = 0x24 + (i * 0x10);
381 is31_write_data(0,pwm_register_array,9); 375 is31_write_data(0,pwm_register_array,9);
382 } 376 }
383 break; 377 break;
384 378
385/* case LED_MSG_SLEEP_LED_ON: 379/* case LED_MSG_SLEEP_LED_ON:
386 // save current settings 380 // save current settings
@@ -415,103 +409,104 @@ page_status = 0; //start frame 0 (all off/on)
415 xprintf("--------------------\n"); 409 xprintf("--------------------\n");
416 chThdSleepMilliseconds(10); 410 chThdSleepMilliseconds(10);
417 } 411 }
418#if DEBUG_ENABLED 412 }
419 uint8_t j; 413}
420 uint8_t pages[3]={0x00, 0x07};
421 //debugging code - print full led/blink/pwm registers on each frame
422 xprintf("----layer state----: %X\n", layer_state);
423 for(i=0;i<2;i++) {
424 xprintf("page: %d\n", pages[i]);
425 chThdSleepMilliseconds(2);
426 for(j=0;j<0x24;j++){
427 if(j > 0 && j % 9 == 0){
428 xprintf("\n");
429 }
430 switch (j) {
431 case 0:
432 xprintf("\n--on-off--\n");
433 chThdSleepMilliseconds(2);
434 break;
435 case 0x12:
436 xprintf("\n--blink--\n");
437 chThdSleepMilliseconds(2);
438 break;
439 }
440 is31_read_register(pages[i],j,&temp);
441 xprintf("%02X, ", temp);
442 chThdSleepMilliseconds(2);
443 }
444 414
445 xprintf("\n--pwm--\n"); 415/* ==============================
446 chThdSleepMilliseconds(2); 416 * debug function
447 for(j=0x24;j<0xB4;j++) { 417 * ============================== */
448 is31_read_register(pages[i],j,&temp); 418void print_debug(uint8_t page) {
449 xprintf("%02X, ", temp); 419 uint8_t j, debug_temp;
450 chThdSleepMilliseconds(2); 420 //debugging code - print full led/blink/pwm registers on each frame
451 if(j > 0x24 && (j-4) % 8 == 0){ 421 xprintf("----layer state----: %X\n", layer_state);
452 xprintf("\n"); 422 xprintf("page: %d\n", page);
453 } 423 chThdSleepMilliseconds(10);
454 } 424 for(j=0;j<0x24;j++){
455 xprintf("\n"); 425 if(j > 0 && j % 9 == 0){
426 xprintf("\n");
427 }
428 switch (j) {
429 case 0:
430 xprintf("\n--on-off--\n");
431 chThdSleepMilliseconds(10);
432 break;
433 case 0x12:
434 xprintf("\n--blink--\n");
435 chThdSleepMilliseconds(10);
436 break;
456 } 437 }
438 is31_read_register(page,j,&debug_temp);
439 xprintf("%02X, ", debug_temp);
440 chThdSleepMilliseconds(10);
441 }
457 442
458 //Function Register 443 xprintf("\n--pwm--\n");
459 xprintf("\n--FUNCTION--\n"); 444 chThdSleepMilliseconds(10);
460 chThdSleepMilliseconds(2); 445 for(j=0x24;j<0xB4;j++) {
461 for(j=0;j<0x0D;j++) { 446 is31_read_register(page,j,&debug_temp);
462 is31_read_register(0x0B,j,&temp); 447 xprintf("%02X, ", debug_temp);
463 switch(j) { 448 chThdSleepMilliseconds(10);
464 case 0: 449 if(j > 0x24 && (j-3) % 8 == 0){
465 xprintf("Config %02X", temp); 450 xprintf("\n");
466 chThdSleepMilliseconds(2); 451 }
467 break; 452 }
468 case 1: 453 xprintf("\n");
469 xprintf(" - Pict %02X\n", temp); 454
470 chThdSleepMilliseconds(2); 455 //Function Register
471 break; 456 xprintf("\n--FUNCTION--\n");
472 case 2: 457 chThdSleepMilliseconds(10);
473 xprintf("Auto1 %02X", temp); 458 for(j=0;j<0x0D;j++) {
474 chThdSleepMilliseconds(2); 459 is31_read_register(0x0B,j,&debug_temp);
475 break; 460 switch(j) {
476 case 3: 461 case 0:
477 xprintf(" - Auto2 %02X\n", temp); 462 xprintf("Config %02X", debug_temp);
478 chThdSleepMilliseconds(2); 463 chThdSleepMilliseconds(2);
479 break; 464 break;
480 case 5: 465 case 1:
481 xprintf("Disp %02X", temp); 466 xprintf(" - Pict %02X\n", debug_temp);
482 chThdSleepMilliseconds(2); 467 chThdSleepMilliseconds(2);
483 break; 468 break;
484 case 6: 469 case 2:
485 xprintf(" - Audio %02X\n", temp); 470 xprintf("Auto1 %02X", debug_temp);
486 chThdSleepMilliseconds(2); 471 chThdSleepMilliseconds(2);
487 break; 472 break;
488 case 7: 473 case 3:
489 xprintf("Frame %02X", temp); 474 xprintf(" - Auto2 %02X\n", debug_temp);
490 chThdSleepMilliseconds(2); 475 chThdSleepMilliseconds(2);
491 break; 476 break;
492 case 8: 477 case 5:
493 xprintf(" - Breath1 %02X\n", temp); 478 xprintf("Disp %02X", debug_temp);
494 chThdSleepMilliseconds(2); 479 chThdSleepMilliseconds(2);
495 break; 480 break;
496 case 9: 481 case 6:
497 xprintf("Breath2 %02X - ", temp); 482 xprintf(" - Audio %02X\n", debug_temp);
498 chThdSleepMilliseconds(2); 483 chThdSleepMilliseconds(2);
499 break; 484 break;
500 case 10: 485 case 7:
501 xprintf(" - Shut %02X\n", temp); 486 xprintf("Frame %02X", debug_temp);
502 chThdSleepMilliseconds(2); 487 chThdSleepMilliseconds(2);
503 break; 488 break;
504 case 11: 489 case 8:
505 xprintf("AGC %02X", temp); 490 xprintf(" - Breath1 %02X\n", debug_temp);
506 chThdSleepMilliseconds(2); 491 chThdSleepMilliseconds(2);
507 break; 492 break;
508 case 12: 493 case 9:
509 xprintf(" - ADC %02X\n", temp); 494 xprintf("Breath2 %02X - ", debug_temp);
510 chThdSleepMilliseconds(2); 495 chThdSleepMilliseconds(2);
511 break; 496 break;
512 } 497 case 10:
498 xprintf(" - Shut %02X\n", debug_temp);
499 chThdSleepMilliseconds(2);
500 break;
501 case 11:
502 xprintf("AGC %02X", debug_temp);
503 chThdSleepMilliseconds(2);
504 break;
505 case 12:
506 xprintf(" - ADC %02X\n", debug_temp);
507 chThdSleepMilliseconds(2);
508 break;
513 } 509 }
514#endif
515 } 510 }
516} 511}
517 512
@@ -523,7 +518,7 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
523 //returns 2 bytes led control register address and byte to write 518 //returns 2 bytes led control register address and byte to write
524 //0 - bit off, 1 - bit on, 2 - toggle bit 519 //0 - bit off, 1 - bit on, 2 - toggle bit
525 520
526 uint8_t control_reg_addr, column_bit, column_byte, temp, blink_on; 521 uint8_t control_reg_addr, column_bit, column_byte, bit_temp, blink_on;
527 522
528 //check for valid led address 523 //check for valid led address
529 if (led_addr < 0 || led_addr > 87 || led_addr % 10 > 8) { 524 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
541 //first byte is led control register address 0x00 536 //first byte is led control register address 0x00
542 //msg_led tens column is pin#, ones column is bit position in 8-bit mask 537 //msg_led tens column is pin#, ones column is bit position in 8-bit mask
543 control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte 538 control_reg_addr = ((led_addr / 10) % 10 - 1 ) * 0x02;// A-register is every other byte
544 xprintf("pre-reg_addr: %X\n", control_reg_addr); 539 xprintf("pre-reg_addr: %2X\n", control_reg_addr);
545 chThdSleepMilliseconds(10); 540 chThdSleepMilliseconds(10);
546 control_reg_addr += blink_on == 1 ? 0x12 : 0x00;//shift 12 bytes to blink register 541 control_reg_addr += blink_on == 1 ? 0x12 : 0x00;//shift 12 bytes to blink register
547 xprintf("blink-reg_addr: %X\n", control_reg_addr); 542 xprintf("blink-reg_addr: %2X\n", control_reg_addr);
543 chThdSleepMilliseconds(10);
544 xprintf("page: %2X\n", page);
548 chThdSleepMilliseconds(10); 545 chThdSleepMilliseconds(10);
549 546
550 column_bit = 1<<(led_addr % 10 - 1);
551 547
552 is31_read_register(page, control_reg_addr, &temp);//maintain status of leds on this byte 548 is31_read_register(page, 0x06, &bit_temp);//maintain status of leds on this byte
553 column_byte = temp; 549 xprintf("reg 06: %2X\n", bit_temp);
550 is31_read_register(page, 0x17, &bit_temp);//maintain status of leds on this byte
551 xprintf("reg 17: %2X\n", bit_temp);
552 is31_read_register(page, 0x18, &bit_temp);//maintain status of leds on this byte
553 xprintf("reg 18: %2X\n", bit_temp);
554 is31_read_register(page, 0x19, &bit_temp);//maintain status of leds on this byte
555 xprintf("reg 19: %2X\n", bit_temp);
556 is31_read_register(page, control_reg_addr, &bit_temp);//maintain status of leds on this byte
557 column_bit = 1<<(led_addr % 10 - 1);
558 column_byte = bit_temp;
554 559
555 xprintf("column_byte read: %X\n", column_byte); 560 xprintf("column_byte read: %2X\n", column_byte);
556 chThdSleepMilliseconds(10); 561 chThdSleepMilliseconds(10);
557 switch(action) { 562 switch(action) {
558 case 0: 563 case 0:
@@ -565,7 +570,7 @@ void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint
565 column_byte ^= column_bit; 570 column_byte ^= column_bit;
566 break; 571 break;
567 } 572 }
568 xprintf("column_byte write: %X\n", column_byte); 573 xprintf("column_byte write: %2X\n", column_byte);
569 chThdSleepMilliseconds(10); 574 chThdSleepMilliseconds(10);
570 575
571 //return word to be written in register 576 //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
574} 579}
575 580
576void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte) { 581void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte) {
577 uint8_t led_control_word[2] = {0};//register address and led on/off mask 582 uint8_t led_control_word[2] = {0};//register address and on/off byte
578 583
579 led_control_word[0] = (row - 1 ) * 0x02;// A-register is every other byte 584 led_control_word[0] = (row - 1 ) * 0x02;// A-register is every other byte
580 led_control_word[1] = led_byte;// A-register is every other byte 585 led_control_word[1] = led_byte;
581 is31_write_data(page, led_control_word, 0x13); 586 is31_write_data(page, led_control_word, 0x02);
582} 587}
583 588
584void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) { 589void write_led_page (uint8_t page, uint8_t *user_led_array, uint8_t led_count) {
585 uint8_t i; 590 uint8_t i;
586 uint8_t pin, col; 591 uint8_t pin, col;
587 uint8_t led_control_register[0x13] = {0};//led control register start address + 0x12 bytes 592 uint8_t led_control_register[0x13] = {0};//control register start address + 0x12 bytes
588 593
589 __builtin_memset(led_control_register,0,13); 594 __builtin_memset(led_control_register,0,13);
590 595
591 for(i=0;i<led_count;i++){ 596 for(i=0;i<led_count;i++){
592 pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1;// 1 byte shift for led register 0x00 address 597 // 1 byte shift for led register 0x00 address
598 pin = ((user_led_array[i] / 10) % 10 - 1 ) * 2 + 1;
593 col = user_led_array[i] % 10 - 1; 599 col = user_led_array[i] % 10 - 1;
594
595 led_control_register[pin] |= 1<<(col); 600 led_control_register[pin] |= 1<<(col);
596 } 601 }
597 602
598 is31_write_data(page, led_control_register, 0x13); 603 is31_write_data(page, led_control_register, 0x13);
599} 604}
600 605
601void set_lock_leds(uint8_t led_addr, uint8_t led_action) { 606void set_lock_leds(uint8_t led_addr, uint8_t led_action, uint8_t page) {
602 uint8_t page, temp; 607 uint8_t lock_temp;
603 uint8_t led_control_word[2] = {0}; 608 uint8_t led_control_word[2] = {0};
604 609
610 xprintf("---set lock---\n");
611 chThdSleepMilliseconds(10);
612
605 //blink if all leds are on 613 //blink if all leds are on
606 //is31_read_register(0, 0x00, &temp); 614 if (page == 0) {
607 //if (temp != 0x00) { 615 is31_read_register(0, 0x00, &lock_temp);
608 // set_led_bit(0,led_control_word,led_addr,(led_action | (1<<2))); //set blink bit 616 xprintf("AllOnReg: %2X\n", lock_temp);
609 //} else { 617 chThdSleepMilliseconds(10);
610 // set_led_bit(0,led_control_word,led_addr,led_action); 618 if (lock_temp == 0xFF) {
611 //} 619 xprintf("AllOntrue\n");
612 //is31_write_data(0, led_control_word, 0x02); 620 chThdSleepMilliseconds(10);
613 621 led_action |= (1<<2); //set blink bit
614 for(page=1; page<8; page++) { 622 } else {
615 set_led_bit(page,led_control_word,led_addr,led_action); 623 xprintf("AllOnfalse\n");
616 is31_write_data(page, led_control_word, 0x02); 624 chThdSleepMilliseconds(10);
625 }
617 } 626 }
627
628 set_led_bit(page,led_control_word,led_addr,led_action);
629
630 xprintf("led_word: %2X", led_control_word[0]);
631 xprintf("%X\n", led_control_word[1]);
632 chThdSleepMilliseconds(10);
633
634 is31_write_data(page, led_control_word, 0x02);
618} 635}
619 636
620/* ===================== 637/* =====================
@@ -639,11 +656,11 @@ void led_controller_init(void) {
639 /* initialise IS31 chip */ 656 /* initialise IS31 chip */
640 is31_init(); 657 is31_init();
641 658
642 //set Display Option Register so all pwm intensity is controlled from Frame 0 659 //set Display Option Register so all pwm intensity is controlled from page 0
643 //enable blink and set blink period to 0.27s x rate 660 //enable blink and set blink period to 0.27s x rate
644 is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME + S31_REG_DISPLAYOPT_BLINK_ENABLE + 5); 661 is31_write_register(IS31_FUNCTIONREG, IS31_REG_DISPLAYOPT, IS31_REG_DISPLAYOPT_INTENSITY_SAME + IS31_REG_DISPLAYOPT_BLINK_ENABLE + 4);
645 662
646 /* set full pwm on Frame 1 */ 663 /* set full pwm on page 1 */
647 pwm_register_array[0] = 0; 664 pwm_register_array[0] = 0;
648 __builtin_memset(pwm_register_array+1, 0xFF, 8); 665 __builtin_memset(pwm_register_array+1, 0xFF, 8);
649 for(i=0; i<8; i++) { 666 for(i=0; i<8; i++) {
diff --git a/keyboards/infinity60/led_controller.h b/keyboards/infinity60/led_controller.h
index 455f06050..7bdef7ae6 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);
31 * ============================*/ 31 * ============================*/
32 32
33void led_controller_init(void); 33void led_controller_init(void);
34void print_debug (uint8_t page);
34 35
35#define CAPS_LOCK_LED_ADDRESS 46 //pin matrix location 36#define CAPS_LOCK_LED_ADDRESS 46 //pin matrix location
36#define NUM_LOCK_LED_ADDRESS 85 37#define NUM_LOCK_LED_ADDRESS 85
@@ -58,7 +59,7 @@ void led_controller_init(void);
58 59
59#define IS31_REG_DISPLAYOPT 0x05 60#define IS31_REG_DISPLAYOPT 0x05
60#define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames 61#define IS31_REG_DISPLAYOPT_INTENSITY_SAME 0x20 // same intensity for all frames
61#define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x8 62#define IS31_REG_DISPLAYOPT_BLINK_ENABLE 0x08
62// D2:D0 bits blink period time (*0.27s) 63// D2:D0 bits blink period time (*0.27s)
63 64
64#define IS31_REG_AUDIOSYNC 0x06 65#define IS31_REG_AUDIOSYNC 0x06
@@ -86,32 +87,33 @@ void led_controller_init(void);
86#define IS31_TIMEOUT 10000 // needs to be long enough to write a whole page 87#define IS31_TIMEOUT 10000 // needs to be long enough to write a whole page
87 88
88/* ======================================== 89/* ========================================
89 * LED Thread related functions/definitions 90 * LED Thread related items
90 * ========================================*/ 91 * ========================================*/
91 92
92extern mailbox_t led_mailbox; 93extern mailbox_t led_mailbox;
93 94
94void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action); 95void set_led_bit (uint8_t page, uint8_t *led_control_reg, uint8_t led_addr, uint8_t action);
95void set_lock_leds (uint8_t led_addr, uint8_t led_action); 96void set_lock_leds (uint8_t led_addr, uint8_t led_action, uint8_t page);
96void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte); 97void write_led_byte (uint8_t page, uint8_t row, uint8_t led_byte);
97void write_led_page (uint8_t page, uint8_t *led_array, uint8_t led_count); 98void write_led_page (uint8_t page, uint8_t *led_array, uint8_t led_count);
98 99
99// constants for signaling the LED controller thread 100// constants for signaling the LED controller thread
100enum led_msg_t { 101enum led_msg_t {
101 KEY_LIGHT, 102 KEY_LIGHT,
102 BLINK_OFF_LED, 103 SET_FULL_ROW,
103 BLINK_ON_LED,
104 BLINK_TOGGLE_LED,
105 OFF_LED, 104 OFF_LED,
106 ON_LED, 105 ON_LED,
107 TOGGLE_LED, 106 TOGGLE_LED,
107 BLINK_OFF_LED,
108 BLINK_ON_LED,
109 BLINK_TOGGLE_LED,
108 TOGGLE_ALL, 110 TOGGLE_ALL,
109 TOGGLE_BACKLIGHT, 111 TOGGLE_BACKLIGHT,
110 DISPLAY_PAGE, 112 DISPLAY_PAGE,
111 RESET_PAGE, 113 RESET_PAGE,
112 TOGGLE_NUM_LOCK, 114 TOGGLE_NUM_LOCK,
113 TOGGLE_CAPS_LOCK, 115 TOGGLE_CAPS_LOCK,
114 MODE_BREATH, 116 TOGGLE_BREATH,
115 STEP_BRIGHTNESS 117 STEP_BRIGHTNESS
116}; 118};
117 119