123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "sd1306.h"
- #include "display.h"
- #include <stdlib.h>
- #include "pico/stdlib.h"
- #include "pico/binary_info.h"
- #include "hardware/i2c.h"
- #include "pico/util/queue.h"
- #include "pico/multicore.h"
- #include "font8x8.h"
- uint8_t display_buffer[OLED_BUF_LEN];
- void display_putchar(char c, uint8_t col_x, uint8_t col_y, bool reverse)
- {
- uint32_t offset = col_x * FONT_WIDTH + OLED_WIDTH * col_y + FONT_WIDTH;
- if( c < 0 ) return;
- if(col_x > 15 || col_y > 3) return;
- // フォントの縦横変換
- for(int i = 0; i < 8 ; i++ ) {
- volatile uint8_t f;
- f = ((font8x8[(int)c][reverse ? 0 : 7] << (reverse ? 7 - i : i)) & 0x80) >> 0;
- f |= ((font8x8[(int)c][reverse ? 1 : 6] << (reverse ? 7 - i : i)) & 0x80) >> 1;
- f |= ((font8x8[(int)c][reverse ? 2 : 5] << (reverse ? 7 - i : i)) & 0x80) >> 2;
- f |= ((font8x8[(int)c][reverse ? 3 : 4] << (reverse ? 7 - i : i)) & 0x80) >> 3;
- f |= ((font8x8[(int)c][reverse ? 4 : 3] << (reverse ? 7 - i : i)) & 0x80) >> 4;
- f |= ((font8x8[(int)c][reverse ? 5 : 2] << (reverse ? 7 - i : i)) & 0x80) >> 5;
- f |= ((font8x8[(int)c][reverse ? 6 : 1] << (reverse ? 7 - i : i)) & 0x80) >> 6;
- f |= ((font8x8[(int)c][reverse ? 7 : 0] << (reverse ? 7 - i : i)) & 0x80) >> 7;
- display_buffer[offset - i] = f;
- }
- }
- void display_putstr(char *str, uint8_t col_x, uint8_t col_y, bool reverse)
- {
- int i = 0;
- while(str[i] != '\0') {
- display_putchar(str[i++], col_x++, col_y, reverse);
- }
- }
- void display(void)
- {
- // I2C初期化
- i2c_init(i2c_default, 800 * 1000);
- // I2Cピン初期化
- gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
- gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
- gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
- gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
- // OLED初期化
- oled_init();
- struct render_area frame_area = {start_col: 0,
- end_col : OLED_WIDTH - 1,
- start_page : 0,
- end_page : OLED_NUM_PAGES - 1,
- buflen : 0 };
- calc_render_area_buflen(&frame_area);
- // ディスプレイクリア
- fill(display_buffer, 0x00);
- while(1) {
- render(display_buffer, &frame_area);
- sleep_us(6*1000);
- }
- }
|