Skip to content

Instantly share code, notes, and snippets.

@melpon
Created April 12, 2019 02:37
Show Gist options
  • Save melpon/e3c003c0c7ed590ffcbc94f515a1c3f4 to your computer and use it in GitHub Desktop.
Save melpon/e3c003c0c7ed590ffcbc94f515a1c3f4 to your computer and use it in GitHub Desktop.
// 有名なビット反転のコード
uint8_t revbits8(uint8_t v) {
v = ((v >> 1) & 0x55) | ((v & 0x55) << 1);
v = ((v >> 2) & 0x33) | ((v & 0x33) << 2);
v = ((v >> 4) & 0x0F) | ((v & 0x0F) << 4);
return v;
}
void screen_render(uint8_t screen[][4]) {
// ここに転送の初期化処理が入る
for (uint8_t row = 0; row < 4; ++row) {
for (uint8_t col = 0; col < 128; ++col) {
uint8_t bits = screen[127 - col][row];
i2c_master_write(revbits8(bits));
}
}
// ここに転送の終了処理が入る
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment