0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

crkbdのOLEDに任意の文字列を書き込む

Last updated at Posted at 2019-12-07

手段

既にssd1306.cによって、1行21文字×4行の文字が書き込めるようになっているので、それを使う。

keymap.cvoid matrix_render_user()の中で、matrix_writeを使って書き込んでいけばよい。
また、一行ごとに書きこみ、matrix->cursorをいい感じに動かしてくれるmatrix_write_lnもある。

keymap.c
void write_hello(struct CharacterMatrix *matrix) {
  matrix->cursor = &matrix->display[0][0];
  matrix_write(matrix, "Hello World!");
}

void matrix_render_user(struct CharacterMatrix *matrix) {
  write_hello(matrix);
}

ssd1306.cのバグで、84文字フルで書き込むと(85文字目を書き込む前に)スクロールしてしまうので、以下のように修正すると4行フルで使える

ssd1306.c
void matrix_write_char_inner(struct CharacterMatrix *matrix, uint8_t c) {
  if (matrix->cursor - &matrix->display[0][0] == sizeof(matrix->display)) {
    // We went off the end; scroll the display upwards by one line
    memmove(&matrix->display[0], &matrix->display[1],
            MatrixCols * (MatrixRows - 1));
    matrix->cursor = &matrix->display[MatrixRows - 1][0];
    memset(matrix->cursor, ' ', MatrixCols);
  }
  *matrix->cursor = c;
  ++matrix->cursor;
}

lib下のkeylogger.clayer_state_reader.cが参考になる。

それ以外の例

Default Layer情報を取得する

persistent_default_layer_set()を使って、デフォルトレイヤーを書き換えてる場合

keymap.c
void write_os(struct CharacterMatrix *matrix) {
  matrix->cursor = &matrix->display[0][0];
  switch (eeconfig_read_default_layer()) {
    case 1 << _WIN:
      matrix_write(matrix, "WIN");
    break;
    case 1 << _MAC:
      matrix_write(matrix, "MAC");
    break;
  }
}

glcdfont.cにWindowsとMacとLinuxとAndroidのアイコンは用意されている。
WindowsとMacのアイコンを書く例

keymap.c
char windows_logo[2][3] = {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}};
char mac_logo[2][3] = {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}};
void write_os(struct CharacterMatrix *matrix) {
  matrix->cursor = &matrix->display[0][0];
  switch (eeconfig_read_default_layer()) {
    case 1 << _QWERTY:
      matrix_write(matrix, windows_logo[0]);
      matrix->cursor = &matrix->display[1][0];
      matrix_write(matrix, windows_logo[1]);
    break;
    case 1 << _MAC:
      matrix_write(matrix, mac_logo[0]);
      matrix->cursor = &matrix->display[1][0];
      matrix_write(matrix, mac_logo[1]);
    break;
  }
}

画像を書き込む

fontファイルglcdfont.cのビットマップをすり替えてしまえばよい。
デフォルトでは、Corneのロゴがセットされている。
また、上記のようにssd1306.cを直しておくと、一行分表示できるサイズが増える

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?