Browse Source

Add basic sleep_led for chibios.

master
flabbergast 8 years ago
parent
commit
dc9fc9a7a4

+ 6
- 6
tmk_core/common/chibios/printf.h View File

@@ -55,16 +55,16 @@ many embedded systems.
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

+ 19
- 0
tmk_core/common/chibios/sleep_led.c View File

@@ -0,0 +1,19 @@
#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
}

+ 1
- 1
tmk_core/common/chibios/timer.c View File

@@ -23,5 +23,5 @@ uint16_t timer_elapsed(uint16_t last)

uint32_t timer_elapsed32(uint32_t last)
{
return ST2MS(chVTTimeElapsedSinceX(MS2ST(last)));
return ST2MS(chVTTimeElapsedSinceX(MS2ST(last)));
}

+ 9
- 4
tmk_core/protocol/chibios/README.md View File

@@ -8,17 +8,22 @@ Also pay attention to `-O0` (enabled for debugging); for deployment use `-O2`.
- 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


+ 25
- 0
tmk_core/protocol/chibios/main.c View File

@@ -48,6 +48,28 @@ host_driver_t chibios_driver = {
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) {
@@ -59,6 +81,9 @@ 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);


+ 2
- 0
tmk_core/protocol/chibios/usb_main.c View File

@@ -23,6 +23,8 @@
#include "debug.h"
#ifdef SLEEP_LED_ENABLE
#include "sleep_led.h"
#include "led.h"
#include "host.h"
#endif

/* ---------------------------------------------------------

+ 3
- 0
tmk_core/protocol/chibios/usb_main.h View File

@@ -19,6 +19,9 @@
#ifndef _USB_MAIN_H_
#define _USB_MAIN_H_

// TESTING
// extern uint8_t blinkLedState;

#include "ch.h"
#include "hal.h"