Topics

k64 rgb-led kernel module


Idupsle <idupsle@...>
 

Hello everybody,

I recently wanted to have a more fun with the k64 and wrote a little kernel
module. I don't know, if it is needed for the real kernel and if the structure
is right. But if anyone is interested in it... here!
Eg:

#include <drivers/k64_rgb.h>
rgb_set_color(0); // set red
rgb_set_color(1); // set green
rgb_set_color(2); // set blue
rgb_set_color(3); // set yellow
rgb_set_color(4); // set cyan
rgb_set_color(5); // set magenta
rgb_set_color(6); // set white
rgb_set_color(7); // set off



diff --git a/drivers/gpio/Kconfig.k64 b/drivers/gpio/Kconfig.k64
index 8854f73..837855a 100644
--- a/drivers/gpio/Kconfig.k64
+++ b/drivers/gpio/Kconfig.k64
@@ -136,4 +136,10 @@ config GPIO_K64_PORTE_PRI
help
K64 Port E IRQ priority

+config GPIO_K64_RGB_LED
+ bool "Freeschale K64-based board LED-RGB driver"
+ depends on GPIO_K64 && CONFIG_PINMUX_DEV_FRDM_K64F
+ default n
+ help
+ K64 Ports for RGB LED.
endif # GPIO_K64
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index f34c0ce..61a815a 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -8,4 +8,6 @@ obj-$(CONFIG_GPIO_SCH) += gpio_sch.o
obj-$(CONFIG_GPIO_QMSI) += gpio_qmsi.o
obj-$(CONFIG_GPIO_ATMEL_SAM3) += gpio_atmel_sam3.o
obj-$(CONFIG_GPIO_K64) += gpio_k64.o
+obj-$(CONFIG_GPIO_K64_RGB_LED) += k64_rgb.o
obj-$(CONFIG_GPIO_STM32) += gpio_stm32.o
+
diff --git a/drivers/gpio/k64_rgb.c b/drivers/gpio/k64_rgb.c
new file mode 100644
index 0000000..06df03d
--- /dev/null
+++ b/drivers/gpio/k64_rgb.c
@@ -0,0 +1,93 @@
+#ifdef CONFIG_GPIO_K64_RGB_LED
+
+#include <errno.h>
+
+#include <nanokernel.h>
+#include <device.h>
+#include <init.h>
+#include <gpio.h>
+#include <sys_io.h>
+#include <soc.h>
+
+#include <pinmux/frdm_k64f/pinmux_k64.h>
+
+#include "gpio_k64.h"
+#include "k64_rgb.h"
+
+void k64_rgb_set_red(uint8_t value)
+{
+ if (value) {
+ sys_set_bit((GPIO_K64_B_BASE_ADDR
+ +GPIO_K64_DIR_OFFSET),
+ K64_PIN_RED%K64_PINMUX_NUM_PINS);
+ } else {
+ sys_clear_bit((GPIO_K64_B_BASE_ADDR
+ +GPIO_K64_DIR_OFFSET),
+ K64_PIN_RED%K64_PINMUX_NUM_PINS);
+ }
+}
+void k64_rgb_set_blue(uint8_t value)
+{
+ if (value) {
+ sys_set_bit((GPIO_K64_B_BASE_ADDR
+ +GPIO_K64_DIR_OFFSET),
+ K64_PIN_BLUE%K64_PINMUX_NUM_PINS);
+ } else {
+ sys_clear_bit((GPIO_K64_B_BASE_ADDR
+ +GPIO_K64_DIR_OFFSET),
+ K64_PIN_BLUE%K64_PINMUX_NUM_PINS);
+ }
+}
+void k64_rgb_set_green(uint8_t value)
+{
+ if (value) {
+ sys_set_bit((GPIO_K64_E_BASE_ADDR
+ +GPIO_K64_DIR_OFFSET),
+ K64_PIN_GREEN%K64_PINMUX_NUM_PINS);
+ } else {
+ sys_clear_bit((GPIO_K64_E_BASE_ADDR
+ +GPIO_K64_DIR_OFFSET),
+ K64_PIN_GREEN%K64_PINMUX_NUM_PINS);
+ }
+}
+
+void k64_rgb_set(uint8_t r, uint8_t g, uint8_t b)
+{
+ k64_rgb_set_red(0);
+ k64_rgb_set_blue(0);
+ k64_rgb_set_green(0);
+ if (r)
+ k64_rgb_set_red(1);
+ if (g)
+ k64_rgb_set_blue(1);
+ if (b)
+ k64_rgb_set_green(1);
+}
+int rgb_set_color(uint8_t color)
+{
+
+ if (color > 7) return 1;
+ switch(color)
+ {
+ case K64_RGB_RED: k64_rgb_set(1, 0, 0);
+ break;
+ case K64_RGB_GREEN: k64_rgb_set(0, 1, 0);
+ break;
+ case K64_RGB_BLUE: k64_rgb_set(0, 0, 1);
+ break;
+ case K64_RGB_YELLOW: k64_rgb_set(1, 1, 0);
+ break;
+ case K64_RGB_CYAN: k64_rgb_set(0, 1, 1);
+ break;
+ case K64_RGB_MAGENTA: k64_rgb_set(1, 0, 1);
+ break;
+ case K64_RGB_WHITE: k64_rgb_set(1, 1, 1);
+ break;
+ case K64_RGB_OFF: k64_rgb_set(0, 0, 0);
+ break;
+ }
+ return 0;
+}
+
+#endif
+
diff --git a/drivers/pinmux/frdm_k64f/pinmux_board_frdm_k64f.c b/drivers/pinmux/frdm_k64f/pinmux_board_frdm_k64f.c
index 9717ef5..9c39b0e 100644
--- a/drivers/pinmux/frdm_k64f/pinmux_board_frdm_k64f.c
+++ b/drivers/pinmux/frdm_k64f/pinmux_board_frdm_k64f.c
@@ -38,11 +38,16 @@
* Since the K64 MCU configures these pins for JTAG/SWD signaling at reset,
* they should only be re-configured if the debug interface is not used.
*/
+#ifdef CONFIG_GPIO_K64_RGB_LED
+#define LED_RGB_PINS 3
+#else
+#define LED_RGB_PINS 0
+#endif

#ifndef CONFIG_PRESERVE_JTAG_IO_PINS
-#define NUM_DFLT_PINS_SET 22
+#define NUM_DFLT_PINS_SET 22 + LED_RGB_PINS
#else
-#define NUM_DFLT_PINS_SET (22 - 3)
+#define NUM_DFLT_PINS_SET (22 - 3) + LED_RGB_PINS
#endif

/*
@@ -58,6 +63,10 @@ struct pin_config mux_config[NUM_DFLT_PINS_SET] = {
#ifndef CONFIG_PRESERVE_JTAG_IO_PINS
{ K64_PIN_PTA1, K64_PINMUX_FUNC_GPIO },
#endif
+#ifdef CONFIG_GPIO_K64_RGB_LED
+ { K64_PIN_PTB21, K64_PINMUX_FUNC_GPIO },
+ { K64_PIN_PTB22, K64_PINMUX_FUNC_GPIO },
+#endif
{ K64_PIN_PTB23, K64_PINMUX_FUNC_GPIO },
#ifndef CONFIG_PRESERVE_JTAG_IO_PINS
{ K64_PIN_PTA2, K64_PINMUX_FUNC_GPIO },
@@ -76,6 +85,9 @@ struct pin_config mux_config[NUM_DFLT_PINS_SET] = {
{ K64_PIN_PTE25, (K64_PINMUX_ALT_5 | K64_PINMUX_OPEN_DRN_ENABLE) },
/* I2C0_SCL */
{ K64_PIN_PTE24, (K64_PINMUX_ALT_5 | K64_PINMUX_OPEN_DRN_ENABLE) },
+#ifdef CONFIG_GPIO_K64_RGB_LED
+ { K64_PIN_PTE26, K64_PINMUX_FUNC_GPIO },
+#endif
{ K64_PIN_PTB2, K64_PINMUX_FUNC_ANALOG }, /* ADC0_SE12/Analog In 0 */
{ K64_PIN_PTB3, K64_PINMUX_FUNC_ANALOG }, /* ADC0_SE13/Analog In 1 */
{ K64_PIN_PTB10, K64_PINMUX_FUNC_ANALOG }, /* ADC1_SE14/Analog In 2 */
diff --git a/drivers/pinmux/frdm_k64f/pinmux_k64.h b/drivers/pinmux/frdm_k64f/pinmux_k64.h
index ca40c14..bc30e25 100644
--- a/drivers/pinmux/frdm_k64f/pinmux_k64.h
+++ b/drivers/pinmux/frdm_k64f/pinmux_k64.h
@@ -280,6 +280,12 @@
#define K64_PIN_PTE30 158
#define K64_PIN_PTE31 159

+#ifdef CONFIG_GPIO_K64_RGB_LED
+#define K64_PIN_RED 54
+#define K64_PIN_GREEN 154
+#define K64_PIN_BLUE 53
+#endif
+
int _fsl_k64_set_pin(uint32_t pin_id, uint32_t func);

int _fsl_k64_get_pin(uint32_t pin_id, uint32_t *func);
diff --git a/include/drivers/k64_rgb.h b/include/drivers/k64_rgb.h
new file mode 100644
index 0000000..de63ae6
--- /dev/null
+++ b/include/drivers/k64_rgb.h
@@ -0,0 +1,39 @@
+#ifndef _K64RGB_H
+#define _K64RGB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#ifdef CONFIG_GPIO_K64_RGB_LED
+//#include "gpio_k64.h"
+#include <gpio.h>
+
+
+/* Available color slsections */
+#define K64_RGB_RED 0
+#define K64_RGB_GREEN 1
+#define K64_RGB_BLUE 2
+#define K64_RGB_YELLOW 3
+#define K64_RGB_CYAN 4
+#define K64_RGB_MAGENTA 5
+#define K64_RGB_WHITE 6
+#define K64_RGB_OFF 7
+
+
+extern int rgb_set_color(uint8_t color);
+//{
+// return k64_rgb_set_color(color);
+//}
+
+
+
+
+#endif /* CONFIG_GPIO_K64_RGB */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _K64RGB_H */