From 85bdc7991ca22ed5367bfad1c6e2073885ec53bf Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Tue, 2 Apr 2019 18:10:17 +0800 Subject: [PATCH] rgb: add initial rgb code It initializes the rgb driver, and can write to its registers. Signed-off-by: Sean Cross --- sw/include/rgb.h | 6 ++++++ sw/src/rgb.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 sw/include/rgb.h create mode 100644 sw/src/rgb.c diff --git a/sw/include/rgb.h b/sw/include/rgb.h new file mode 100644 index 0000000..da5b342 --- /dev/null +++ b/sw/include/rgb.h @@ -0,0 +1,6 @@ +#ifndef _RGB_H_ +#define _RGB_H_ + +void rgb_init(void); + +#endif /* _RGB_H_ */ \ No newline at end of file diff --git a/sw/src/rgb.c b/sw/src/rgb.c new file mode 100644 index 0000000..46d1e50 --- /dev/null +++ b/sw/src/rgb.c @@ -0,0 +1,46 @@ +#include +#include + +enum led_registers { + LEDDCR0 = 8, + LEDDBR = 9, + LEDDONR = 10, + LEDDOFR = 11, + LEDDBCRR = 5, + LEDDBCFR = 6, + LEDDPWRR = 1, + LEDDPWRG = 2, + LEDDPWRB = 3, +}; + +#define BREATHE_ENABLE (1 << 7) +#define BREATHE_EDGE_ON (0 << 6) +#define BREATHE_EDGE_BOTH (1 << 6) +#define BREATHE_MODE_MODULATE (1 << 5) +#define BREATHE_RATE(x) ((x & 7) << 0) + +static void rgb_write(uint8_t value, uint8_t addr) { + rgb_addr_write(addr); + rgb_dat_write(value); +} + +void rgb_init(void) { + // Turn on the RGB block and current enable, as well as enabling led control + rgb_ctrl_write((1 << 0) | (1 << 1) | (1 << 2)); + + rgb_write((1 << 7) | (1 << 6), LEDDCR0); + + // Set clock register to 12 MHz / 64 kHz - 1 + rgb_write((12000000/64000)-1, LEDDBR); + + rgb_write(12, LEDDONR); + rgb_write(24, LEDDOFR); + + rgb_write(BREATHE_ENABLE | BREATHE_EDGE_BOTH + | BREATHE_MODE_MODULATE | BREATHE_RATE(2), LEDDBCRR); + rgb_write(BREATHE_ENABLE | BREATHE_MODE_MODULATE | BREATHE_RATE(3), LEDDBCFR); + + rgb_write(0x00/4, LEDDPWRG); // Red + rgb_write(0x4a/4, LEDDPWRB); // Green + rgb_write(0xe1/4, LEDDPWRR); // Blue +} \ No newline at end of file