display.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "display.h"
  2. #include <stdlib.h>
  3. #include "pico/stdlib.h"
  4. #include "pico/binary_info.h"
  5. #include "hardware/i2c.h"
  6. #include "pico/util/queue.h"
  7. #include "pico/multicore.h"
  8. // #include "font8x8.h"
  9. uint8_t display_buffer[OLED_BUF_LEN];
  10. void display_putchar(char c, uint8_t col_x, uint8_t col_y, bool reverse)
  11. {
  12. uint32_t offset = col_x * FONT_WIDTH + OLED_WIDTH * col_y + FONT_WIDTH;
  13. if( c < 0 ) return;
  14. if(col_x > 15 || col_y > 3) return;
  15. // フォントの縦横変換
  16. for(int i = 0; i < 8 ; i++ ) {
  17. volatile uint8_t f;
  18. f = ((font8x8[(int)c][reverse ? 0 : 7] << (reverse ? 7 - i : i)) & 0x80) >> 0;
  19. f |= ((font8x8[(int)c][reverse ? 1 : 6] << (reverse ? 7 - i : i)) & 0x80) >> 1;
  20. f |= ((font8x8[(int)c][reverse ? 2 : 5] << (reverse ? 7 - i : i)) & 0x80) >> 2;
  21. f |= ((font8x8[(int)c][reverse ? 3 : 4] << (reverse ? 7 - i : i)) & 0x80) >> 3;
  22. f |= ((font8x8[(int)c][reverse ? 4 : 3] << (reverse ? 7 - i : i)) & 0x80) >> 4;
  23. f |= ((font8x8[(int)c][reverse ? 5 : 2] << (reverse ? 7 - i : i)) & 0x80) >> 5;
  24. f |= ((font8x8[(int)c][reverse ? 6 : 1] << (reverse ? 7 - i : i)) & 0x80) >> 6;
  25. f |= ((font8x8[(int)c][reverse ? 7 : 0] << (reverse ? 7 - i : i)) & 0x80) >> 7;
  26. display_buffer[offset - i] = f;
  27. }
  28. }
  29. void display_putstr(char *str, uint8_t col_x, uint8_t col_y, bool reverse)
  30. {
  31. int i = 0;
  32. while(str[i] != '\0') {
  33. display_putchar(str[i++], col_x++, col_y, reverse);
  34. }
  35. }
  36. void display_clear(void)
  37. {
  38. fill(display_buffer, 0x00);
  39. }
  40. void display_main(void)
  41. {
  42. // I2C初期化
  43. i2c_init(i2c_default, 800 * 1000);
  44. // I2Cピン初期化
  45. gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
  46. gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
  47. gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
  48. gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
  49. // OLED初期化
  50. oled_init();
  51. struct render_area frame_area = {start_col: 0,
  52. end_col : OLED_WIDTH - 1,
  53. start_page : 0,
  54. end_page : OLED_NUM_PAGES - 1,
  55. buflen : 0 };
  56. calc_render_area_buflen(&frame_area);
  57. // ディスプレイクリア
  58. fill(display_buffer, 0x00);
  59. while(true) {
  60. render(display_buffer, &frame_area);
  61. sleep_us(6*1000);
  62. }
  63. }
  64. void display_init(void)
  65. {
  66. multicore_reset_core1();
  67. multicore_launch_core1(display_main);
  68. }