1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/minimal-examples/embedded/lws-minimal-esp32/scan/scan.c
Andy Green 15ce46d971 drivers: initial generic gpio and i2c plus bitbang
Make a start on generic peripheral and bus drivers to provide
meta-functionality regardless of platform.

On the one hand this simply provides...

 - bitbang i2c on top of esp-idf gpio apis
 - ssd1306 oled chip driver as found on Heltec WB32
 - modifications to the minimal example test for esp32 to use that

... on the other hand, those capabilities are provided by creating:

 - an abstract i2c class object
 - an abstract gpio class object
 - i2c class implementation using the abstract gpio for bitbang
 - an abstract display class object
 - an abstract display state (brightness, animated change,
    on/off/init tracking, autodim after inactive, auto-off /
    blanking after inactive)

... with the intention, eg, you only have to add a platform
implementation for the gpio to be able to use the i2c-based
display drivers and state handling, and i2c bitbang, without
any other modifications.
2020-06-10 19:17:08 +01:00

70 lines
1.6 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
/*
* The bitmap mapping for the framebuffer is from top left to right, a strip of 8 vertical
* bits from each byte, so there is a block of 128 x 8 px on a stride of 128 bytes.
*
* The 8 bits from the first byte in the fb are the leftmost vertical strip of 8, then the
* next byte is the 8 pixels one to the right, until the 127th byte if the vertical strip
* of 8 on the rhs.
*
* +----------------------------------+
* |0 |
* |1 |
* |2 |
* |3 |
* |4 |
* |5 |
* |6 |
* |7 |
*
* In this way the fb is more like (8 x vertical (128 x 8))
*
*/
static const uint8_t scan[] = {
#include "pic.h"
};
/*
* input byte 0 is like ABCDEFGH, one bit per horizontal pixel for one line
* on an hstride of 16 bytes
*
* output byte 0 = b0 = byte 0 b0, b1 = byte16 b0, b2 = byte24 b0 etc
*
* px(0,0) --> byte0 b0
* px(0,1) --> byte0 b1
*/
int
main(void)
{
const uint8_t *p = scan;
uint8_t r[1024];
int x, y, t = 0;
memset(&r, 0, sizeof(r));
while (t < 1024) {
for (x = 0; x < 128; x++) {
for (y = 0; y < 8; y++) {
if (p[t + (16 * y) + (x / 8)] & (1 << (7 - (x & 7))))
r[t + x] |= 1 << y;
}
}
t += 128;
}
for (x = 0; x < 1024; x++) {
printf("0x%02X, ", r[x]);
if ((x & 0xf) == 0xf)
printf("\n");
}
}