diodes.c 986 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #define BITS_PER_SUBCOLOR 8
  4. #define BITS_PER_COLOR (BITS_PER_SUBCOLOR*3)
  5. // uncomment this line to reverse bit order
  6. //#define BIT_ORDER_REVERSE
  7. // Set only one color
  8. void gen_cmd_setc(uint8_t *buf, char c)
  9. {
  10. uint8_t b = 1;
  11. #ifdef BIT_ORDER_REVERSE
  12. uint8_t *p = buf;
  13. #else
  14. uint8_t *p = &buf[BITS_PER_SUBCOLOR-1];
  15. #endif
  16. while (b) {
  17. *p = c&b ? 14 : 8;
  18. #ifdef BIT_ORDER_REVERSE
  19. p++;
  20. #else
  21. p--;
  22. #endif
  23. b <<= 1;
  24. }
  25. return;
  26. }
  27. void gen_cmd_setrgb(uint8_t *buf, char r, char g, char b)
  28. {
  29. gen_cmd_setc( buf, r);
  30. gen_cmd_setc(&buf[ BITS_PER_SUBCOLOR], g);
  31. gen_cmd_setc(&buf[2*BITS_PER_SUBCOLOR], b);
  32. return;
  33. }
  34. int main()
  35. {
  36. uint8_t cmd[BITS_PER_COLOR];
  37. gen_cmd_setrgb(cmd, 255, 1, 128);
  38. /*
  39. int r = blahblah_Transmit(&someWhere, &cmd, BITS_PER_COLOR);
  40. if (r != HAL_OK) {
  41. blink_alaRRM_leds();
  42. }
  43. */
  44. int i=0;
  45. while (i < BITS_PER_COLOR)
  46. printf("% 3i", cmd[i++]);
  47. printf("\n");
  48. return 0;
  49. }