To use the printf you need to supply your own character output function,
something like :
- void putc ( void* p, char c)
- {
- while (!SERIAL_PORT_EMPTY) ;
- SERIAL_PORT_TX_REGISTER = c;
- }
+ void putc ( void* p, char c)
+ {
+ while (!SERIAL_PORT_EMPTY) ;
+ SERIAL_PORT_TX_REGISTER = c;
+ }
Before you can call printf you need to initialize it to use your
character output function with something like:
- init_printf(NULL,putc);
+ init_printf(NULL,putc);
Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
the NULL (or any pointer) you pass into the 'init_printf' will eventually be
--- /dev/null
+#include "ch.h"
+
+#include "led.h"
+#include "sleep_led.h"
+
+void sleep_led_init(void) {
+}
+
+void sleep_led_enable(void) {
+ led_set(1<<USB_LED_CAPS_LOCK);
+}
+
+void sleep_led_disable(void) {
+ led_set(0);
+}
+
+void sleep_led_toggle(void) {
+ // not working yet, state not saved anywhere currently
+}
uint32_t timer_elapsed32(uint32_t last)
{
- return ST2MS(chVTTimeElapsedSinceX(MS2ST(last)));
+ return ST2MS(chVTTimeElapsedSinceX(MS2ST(last)));
}
- USB string descriptors are a mess. I did not find a way to cleanly generate the right structures from actual strings, so the definitions in individual keyboards' `config.h` are ugly as heck.
- There are some random constants left so far, e.g. 5ms sleep between calling `keyboard_task` in `main.c`. There should be no such in `usb_main.c`. Everything is based on timers/interrupts/kernel scheduling (well except `keyboard_task`), so no periodically called things (again, except `keyboard_task`, which is just how TMK is designed).
- It is easy to add some code for testing (e.g. blink LED, do stuff on button press, etc...) - just create another thread in `main.c`, it will run independently of the keyboard business.
-- Jumping to bootloader works, but it is not entirely pleasant, since it is very much MCU dependent. So, one needs to dig out the right address to jump to, and pass it to the compiler in the `Makefile`. Also, a patch to upstream ChibiOS is needed (supplied), because it `ResetHandler` needs adjusting.
+- Jumping to bootloader works, but it is not entirely pleasant, since it is very much MCU dependent. The code is now geared towards STM32 chips and their built-in bootloaders. So, one needs to dig out the right address to jump to, and pass it to the compiler in the `Makefile`. Also, a patch to upstream ChibiOS is needed (supplied), because it `ResetHandler` needs adjusting.
+- Sleep LED works, but at the moment only on/off, i.e. no breathing.
- The USB stack works pretty completely; however there are bits of other TMK stuff that are not done yet:
### Immediate todo
-- suspend
-- sleep led
+- power saving for suspend?
+- PWM for sleep led
+
+### Not tested, but possibly working
+
+- backlight
### Missing / not working (TMK vs ChibiOS bits)
-- eeprom / bootmagic (will be chip dependent)
+- eeprom / bootmagic (will be chip dependent; eeprom needs to be emulated in flash, which means less writes; wear-levelling?)
### Tried with
send_consumer
};
+
+/* TESTING
+ * Amber LED blinker thread, times are in milliseconds.
+ */
+// uint8_t blinkLedState = 0;
+// static THD_WORKING_AREA(waThread1, 128);
+// static THD_FUNCTION(Thread1, arg) {
+// (void)arg;
+// chRegSetThreadName("blinker1");
+// while(true) {
+// if(blinkLedState) {
+// blinkLedState = 0;
+// palSetPad(GPIOC, GPIOC_LED_ORANGE);
+// chThdSleepMilliseconds(100);
+// palClearPad(GPIOC, GPIOC_LED_ORANGE);
+// }
+// chThdSleepMilliseconds(100);
+// }
+// }
+
+
+
/* Main thread
*/
int main(void) {
chThdSleepMilliseconds(400);
palClearPad(GPIOC, GPIOC_LED_BLUE);
+ // TESTING
+ // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+
/* Init USB */
init_usb_driver(&USB_DRIVER);
#include "debug.h"
#ifdef SLEEP_LED_ENABLE
#include "sleep_led.h"
+#include "led.h"
+#include "host.h"
#endif
/* ---------------------------------------------------------
#ifndef _USB_MAIN_H_
#define _USB_MAIN_H_
+// TESTING
+// extern uint8_t blinkLedState;
+
#include "ch.h"
#include "hal.h"