Created
June 1, 2016 05:19
-
-
Save monpetit/0445940a85b903e440e19a10ef0b2ea5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <stdint.h> | |
| typedef uint8_t u08; | |
| #define RAND8() (rand() % 256) | |
| #define RGB_LED_PORT (gpioPortE) | |
| #define RGB_LED_PIN (11) | |
| #define LED_HI() GPIO_PinOutSet(RGB_LED_PORT, RGB_LED_PIN) | |
| #define LED_LO() GPIO_PinOutClear(RGB_LED_PORT, RGB_LED_PIN) | |
| __STATIC_INLINE void T0H(void) | |
| { | |
| LED_HI(); | |
| __ASM volatile ("nop; nop; nop; nop; nop; nop;"); // 350 ns | |
| } | |
| __STATIC_INLINE void T1H(void) | |
| { | |
| LED_HI(); | |
| __ASM volatile ("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;" | |
| "nop; nop;"); // 700 ns | |
| } | |
| __STATIC_INLINE void T0L(void) | |
| { | |
| LED_LO(); | |
| __ASM volatile ("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;" | |
| "nop; nop; nop; nop;"); // 800 ns | |
| } | |
| __STATIC_INLINE void T1L(void) | |
| { | |
| LED_LO(); | |
| __ASM volatile ("nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop;"); // 600 ns | |
| } | |
| __STATIC_INLINE void T1(void) | |
| { | |
| T1H(); | |
| T1L(); | |
| } | |
| __STATIC_INLINE void T0(void) | |
| { | |
| T0H(); | |
| T0L(); | |
| } | |
| __STATIC_INLINE void show_rgb(volatile u08 r, volatile u08 g, volatile u08 b) | |
| { | |
| int i; | |
| for (i = 0; i < 8; i++) { | |
| if (r & 0x80) | |
| T1(); | |
| else | |
| T0(); | |
| r = (r << 1); | |
| } | |
| for (i = 0; i < 8; i++) { | |
| if (g & 0x80) | |
| T1(); | |
| else | |
| T0(); | |
| g = (g << 1); | |
| } | |
| for (i = 0; i < 8; i++) { | |
| if (b & 0x80) | |
| T1(); | |
| else | |
| T0(); | |
| b = (b << 1); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment