1
0
Fork 0
mirror of https://libwebsockets.org/repo/libwebsockets synced 2025-05-03 15:39:53 +00:00

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.
This commit is contained in:
Andy Green 2020-06-10 19:17:08 +01:00
parent ad5a4f7040
commit 15ce46d971
27 changed files with 1401 additions and 20 deletions

View file

@ -152,6 +152,12 @@ option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
option(LWS_WITH_LIBEVENT "Compile with support for libevent" OFF)
option(LWS_WITH_GLIB "Compile with support for glib event loop" OFF)
#
# LWS Drivers
#
option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" OFF)
#
# Static / Dynamic build options
#

View file

@ -609,6 +609,14 @@ struct lws;
#endif
#include <libwebsockets/lws-display.h>
#include <libwebsockets/lws-i2c.h>
#include <libwebsockets/lws-gpio.h>
#include <libwebsockets/lws-bb-i2c.h>
#include <libwebsockets/lws-ssd1306-i2c.h>
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,66 @@
/*
* I2C - bitbanged generic gpio implementation
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* This is like an abstract class for gpio, a real implementation provides
* functions for the ops that use the underlying OS gpio arrangements.
*/
typedef struct lws_bb_i2c {
lws_i2c_ops_t bb_ops; /* init to lws_bb_i2c_ops */
/* implementation-specific members */
_lws_plat_gpio_t scl;
_lws_plat_gpio_t sda;
const lws_gpio_ops_t *gpio;
void (*delay)(void);
} lws_bb_i2c_t;
#define lws_bb_i2c_ops \
{ \
.init = lws_bb_i2c_init, \
.start = lws_bb_i2c_start, \
.stop = lws_bb_i2c_stop, \
.write = lws_bb_i2c_write, \
.read = lws_bb_i2c_read, \
.set_ack = lws_bb_i2c_set_ack, \
}
int
lws_bb_i2c_init(const lws_i2c_ops_t *octx);
int
lws_bb_i2c_start(const lws_i2c_ops_t *octx);
void
lws_bb_i2c_stop(const lws_i2c_ops_t *octx);
int
lws_bb_i2c_write(const lws_i2c_ops_t *octx, uint8_t data);
int
lws_bb_i2c_read(const lws_i2c_ops_t *octx);
void
lws_bb_i2c_set_ack(const lws_i2c_ops_t *octx, int ack);

View file

@ -0,0 +1,140 @@
/*
* lws abstract display
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#if !defined(__LWS_DISPLAY_H__)
#define __LWS_DISPLAY_H__
#include <stdint.h>
typedef uint16_t lws_display_scalar;
typedef uint8_t lws_display_brightness;
/*
* This is embedded in the actual display implementation object at the top,
* so a pointer to this can be cast to a pointer to the implementation object
* by any code that is specific to how it was implemented.
*/
typedef struct lws_display {
int (*init)(const struct lws_display *disp);
int (*brightness)(const struct lws_display *disp, lws_display_brightness b);
int (*blit)(const struct lws_display *disp, const uint8_t *src,
lws_display_scalar x, lws_display_scalar y,
lws_display_scalar w, lws_display_scalar h);
int (*power)(const struct lws_display *disp, int state);
void *variant;
lws_display_scalar w;
lws_display_scalar h;
} lws_display_t;
/*
* This contains dynamic data related to display state
*/
enum lws_display_state {
LWSDISPS_OFF, /* managed in display_state */
LWSDISPS_AUTODIMMED,
LWSDISPS_ACTIVE,
};
typedef struct lws_diplay_state {
lws_sorted_usec_list_t sul;
lws_sorted_usec_list_t sul_autodim;
const lws_display_t *disp;
struct lws_context *ctx;
int autodim_ms;
int off_ms;
lws_display_brightness bl_current;
lws_display_brightness bl_target;
lws_display_brightness bl_step;
lws_display_brightness bl_active;
lws_display_brightness bl_dim;
enum lws_display_state state;
} lws_display_state_t;
/**
* lws_display_state_init() - initialize display states
*
* \param lds: the display state object
* \param ctx: the lws context
* \param autodim_ms: ms since last active report to dim display (<0 = never)
* \param off_ms: ms since dim to turn display off (<0 = never)
* \param active: brightness level to use when active (0-255)
* \param dim: brightness level to use when dim (0-255)
* \param disp: generic display object we belong to
*
* This initializes a display's state, and sets up the optional screen auto-dim
* and blanking on inactive, and gradual brightness change timer.
*
* - auto-dim then off: set autodim to some ms and off_ms to some ms
* - auto-dim only: set autodim to some ms and off_ms to -1
* - off-only: set autodim to some ms and off_ms to 0
* - neither: set both autodim and off_ms to -1
*/
void
lws_display_state_init(lws_display_state_t *lds, struct lws_context *ctx,
int autodim_ms, int off_ms, lws_display_brightness active,
lws_display_brightness dim, const lws_display_t *disp);
/**
* lws_display_state_set_brightness() - gradually change the brightness
*
* \param lds: the display state we are changing
* \param target: the target brightness
* \param step: the step change for each gradual brightness change
*
* Adjusts the brightness gradually twoards the target at 20Hz
*/
void
lws_display_state_set_brightness(lws_display_state_t *lds,
lws_display_brightness target,
lws_display_brightness step);
/*
* lws_display_state_active() - inform the system the display is active
*
* \param lds: the display state we are marking as active
*
* Resets the auto-dim and auto-off timers and makes sure the display is on and
* at the active brightness level
*/
void
lws_display_state_active(lws_display_state_t *lds);
/*
* lws_display_state_off() - turns off the related display
*
* \param lds: the display state we are turning off
*
* Turns the display to least power mode or completely off if possible.
* Disables the timers related to dimming and blanking.
*/
void
lws_display_state_off(lws_display_state_t *lds);
#endif

View file

@ -150,3 +150,7 @@ extern uint16_t lws_esp32_sine_interp(int n);
/* required in external code by esp32 plat (may just return if no leds) */
extern void lws_esp32_leds_timer_cb(TimerHandle_t th);
#include "libwebsockets/lws-gpio.h"
extern const lws_gpio_ops_t lws_gpio_plat;

View file

@ -0,0 +1,60 @@
/*
* Generic GPIO ops
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* This is like an abstract class for gpio, a real implementation provides
* functions for the ops that use the underlying OS gpio arrangements.
*/
#if !defined(__LWS_GPIO_H__)
#define __LWS_GPIO_H__
typedef int _lws_plat_gpio_t;
typedef enum {
LWSGGPIO_IRQ_NONE,
LWSGGPIO_IRQ_RISING,
LWSGGPIO_IRQ_FALLING,
LWSGGPIO_IRQ_CHANGE,
LWSGGPIO_IRQ_LOW,
LWSGGPIO_IRQ_HIGH
} lws_gpio_irq_t;
enum {
LWSGGPIO_FL_READ = (1 << 0),
LWSGGPIO_FL_WRITE = (1 << 1),
LWSGGPIO_FL_PULLUP = (1 << 2),
LWSGGPIO_FL_PULLDOWN = (1 << 3),
LWSGGPIO_FL_START_LOW = (1 << 4),
};
typedef void (*lws_gpio_irq_cb_t)(void *arg);
typedef struct lws_gpio_ops {
void (*mode)(_lws_plat_gpio_t gpio, int flags);
int (*read)(_lws_plat_gpio_t gpio);
void (*set)(_lws_plat_gpio_t gpio, int val);
int (*irq_mode)(_lws_plat_gpio_t gpio, lws_gpio_irq_t irq,
lws_gpio_irq_cb_t cb, void *arg);
} lws_gpio_ops_t;
#endif

View file

@ -0,0 +1,54 @@
/*
* Generic I2C ops
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* This is like an abstract class for i2c, a real implementation provides
* functions for the ops that use the underlying OS arrangements.
*/
#if !defined(__LWS_I2C_H__)
#define __LWS_I2C_H__
#include <stdint.h>
#include <stddef.h>
typedef struct lws_i2c_ops {
int (*init)(const struct lws_i2c_ops *ctx);
int (*start)(const struct lws_i2c_ops *ctx);
void (*stop)(const struct lws_i2c_ops *ctx);
int (*write)(const struct lws_i2c_ops *ctx, uint8_t data);
int (*read)(const struct lws_i2c_ops *ctx);
void (*set_ack)(const struct lws_i2c_ops *octx, int ack);
} lws_i2c_ops_t;
/*
* These are implemented by calling the ops above, and so are generic
*/
int
lws_i2c_command(const lws_i2c_ops_t *ctx, uint8_t ads7, uint8_t c);
int
lws_i2c_command_list(const lws_i2c_ops_t *ctx, uint8_t ads7, const uint8_t *buf,
size_t len);
#endif

View file

@ -0,0 +1,64 @@
/*
* lws abstract display implementation for ssd1306 on i2c
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#if !defined(__LWS_DISPLAY_SSD1306_I2C_H__)
#define __LWS_DISPLAY_SSD1306_I2C_H__
/*
* D/C# pin on SSD1306 sets the I2C slave ads
* from these two options (7-bit address)
*/
#define SSD1306_I2C7_ADS1 0x3c
#define SSD1306_I2C7_ADS2 0x3d
typedef struct lws_display_ssd1306 {
lws_display_t disp; /* use lws_display_ssd1306_ops to set ops */
const lws_i2c_ops_t *i2c; /* i2c ops */
const lws_gpio_ops_t *gpio; /* NULL or gpio ops */
_lws_plat_gpio_t reset_gpio; /* if gpio ops, nReset gpio # */
uint8_t i2c7_address; /* one of SSD1306_I2C7_ADS... */
} lws_display_ssd1306_t;
int
lws_display_ssd1306_i2c_init(const struct lws_display *disp);
int
lws_display_ssd1306_i2c_brightness(const struct lws_display *disp, uint8_t b);
int
lws_display_ssd1306_i2c_blit(const struct lws_display *disp, const uint8_t *src,
lws_display_scalar x, lws_display_scalar y,
lws_display_scalar w, lws_display_scalar h);
int
lws_display_ssd1306_i2c_power(const struct lws_display *disp, int state);
#define lws_display_ssd1306_ops \
.init = lws_display_ssd1306_i2c_init, \
.brightness = lws_display_ssd1306_i2c_brightness, \
.blit = lws_display_ssd1306_i2c_blit, \
.power = lws_display_ssd1306_i2c_power
#endif

View file

@ -122,6 +122,10 @@ add_subdir_include_dirs(misc)
add_subdir_include_dirs(system)
add_subdir_include_dirs(event-libs)
if (LWS_WITH_DRIVERS)
add_subdir_include_dirs(drivers)
endif()
if (LWS_WITH_NETWORK)
add_subdir_include_dirs(core-net)
if (LWS_WITH_ABSTRACT)

View file

@ -0,0 +1,14 @@
list(APPEND SOURCES
drivers/display/lws-display.c
drivers/display/ssd1306-i2c.c
drivers/i2c/lws-i2c.c
drivers/i2c/bitbang/lws-bb-i2c.c
)
if (LWS_ESP_PLATFORM)
list(APPEND SOURCES
plat/freertos/esp32/drivers/gpio-esp32.c)
endif()
exports_to_parent_scope()

View file

@ -0,0 +1,66 @@
/*
* Private register map for SSD1306
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#if !defined(__LWS_SSD1306_H__)
#define __LWS_SSD1306_H__
enum {
SSD1306_SETLOWCOLUMN = 0x00,
SSD1306_SETHIGHCOLUMN = 0x10,
SSD1306_MEMORYMODE = 0x20,
SSD1306_COLUMNADDR = 0x21,
SSD1306_PAGEADDR = 0x22,
SSD1306_DEACTIVATE_SCROLL = 0x2e,
SSD1306_SETSTARTLINE = 0x40,
SSD1306_SETCONTRAST = 0x81,
SSD1306_CHARGEPUMP = 0x8d,
SSD1306_SEGREMAP = 0xa0,
SSD1306_SETSEGMENTREMAP = 0xa1,
SSD1306_DISPLAYALLON_RESUME = 0xa4,
SSD1306_DISPLAYALLON = 0xa5,
SSD1306_NORMALDISPLAY = 0xa6,
SSD1306_INVERTDISPLAY = 0xa7,
SSD1306_SETMULTIPLEX = 0xa8,
SSD1306_DISPLAYOFF = 0xae,
SSD1306_DISPLAYON = 0xaf,
SSD1306_COMSCANINC = 0xc0,
SSD1306_COMSCANDEC = 0xc8,
SSD1306_SETDISPLAYOFFSET = 0xd3,
SSD1306_SETDISPLAYCLOCKDIV = 0xd5,
SSD1306_SETPRECHARGE = 0xd9,
SSD1306_SETCOMPINS = 0xda,
SSD1306_SETVCOMDESELECT = 0xdb,
SSD1306_NOP = 0xe3,
};
#endif

View file

@ -0,0 +1,126 @@
/*
* lws abstract display
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <libwebsockets.h>
static void
sul_cb(lws_sorted_usec_list_t *sul)
{
lws_display_state_t *lds = lws_container_of(sul, lws_display_state_t,
sul);
if (lds->bl_target > lds->bl_current) {
if (lds->bl_target - lds->bl_current < lds->bl_step)
lds->bl_current = lds->bl_target;
else
lds->bl_current += lds->bl_step;
} else {
if (lds->bl_current - lds->bl_target < lds->bl_step)
lds->bl_current = lds->bl_target;
else
lds->bl_current -= lds->bl_step;
}
lds->disp->brightness(lds->disp, lds->bl_current);
if (lds->bl_current != lds->bl_target)
/*
* Come back and move towards the target again in 50ms
*/
lws_sul_schedule(lds->ctx, 0, &lds->sul,
sul_cb, 50 * LWS_US_PER_MS);
}
static void
sul_autodim_cb(lws_sorted_usec_list_t *sul)
{
lws_display_state_t *lds = lws_container_of(sul, lws_display_state_t,
sul_autodim);
/* we fire both to dim and to blank... if already in dim state, blank */
if (lds->state == LWSDISPS_AUTODIMMED) {
lws_display_state_off(lds);
return;
}
lds->state = LWSDISPS_AUTODIMMED;
lws_display_state_set_brightness(lds, lds->bl_dim, lds->bl_step);
if (lds->off_ms >= 0)
lws_sul_schedule(lds->ctx, 0, &lds->sul_autodim, sul_autodim_cb,
lds->off_ms * LWS_US_PER_MS);
}
void
lws_display_state_init(lws_display_state_t *ds, struct lws_context *ctx,
int dim_ms, int off_ms, lws_display_brightness active,
lws_display_brightness dim, const lws_display_t *disp)
{
memset(ds, 0, sizeof(*ds));
ds->disp = disp;
ds->ctx = ctx;
ds->autodim_ms = dim_ms;
ds->off_ms = off_ms;
ds->bl_active = active;
ds->bl_dim = dim;
}
void
lws_display_state_set_brightness(lws_display_state_t *lds,
lws_display_brightness target,
lws_display_brightness step)
{
lds->bl_target = target;
lds->bl_step = step;
lws_sul_schedule(lds->ctx, 0, &lds->sul, sul_cb, 1);
}
void
lws_display_state_active(lws_display_state_t *lds)
{
if (lds->state == LWSDISPS_OFF)
lds->disp->power(lds->disp, 1);
if (lds->bl_current != lds->bl_active)
lws_display_state_set_brightness(lds, lds->bl_active, 2);
/* reset the autodim timer */
if (lds->autodim_ms >= 0)
lws_sul_schedule(lds->ctx, 0, &lds->sul_autodim, sul_autodim_cb,
lds->autodim_ms * LWS_US_PER_MS);
lds->state = LWSDISPS_ACTIVE;
}
void
lws_display_state_off(lws_display_state_t *lds)
{
lds->disp->power(lds->disp, 0);
lws_sul_cancel(&lds->sul);
lws_sul_cancel(&lds->sul_autodim);
lds->bl_current = 0;
lds->state = LWSDISPS_OFF;
}

View file

@ -0,0 +1,151 @@
/*
* lws abstract display implementation for ssd1306 on i2c
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <libwebsockets.h>
#include <drivers/devices/display/ssd1306.h>
static uint8_t ssd1306_128x64_init[] = {
SSD1306_DISPLAYOFF,
SSD1306_SETDISPLAYCLOCKDIV, 0xf0,
SSD1306_SETMULTIPLEX, 64 - 1,
SSD1306_SETDISPLAYOFFSET, 0,
SSD1306_CHARGEPUMP, 0x14,
SSD1306_MEMORYMODE, 0,
SSD1306_SEGREMAP | (0 << 0),
SSD1306_COMSCANDEC,
SSD1306_SETCOMPINS, (1 << 4) | 0x02,
SSD1306_SETCONTRAST, 0, /* start at lowest */
SSD1306_SETPRECHARGE, (0xf << 4) | (1 << 0),
SSD1306_SETVCOMDESELECT, (4 << 4),
SSD1306_DEACTIVATE_SCROLL,
SSD1306_DISPLAYALLON_RESUME,
SSD1306_NORMALDISPLAY,
SSD1306_DISPLAYON
};
int
lws_display_ssd1306_i2c_init(const struct lws_display *disp)
{
const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp;
si->i2c->init(si->i2c);
if (si->gpio) {
si->gpio->mode(si->reset_gpio, LWSGGPIO_FL_WRITE |
LWSGGPIO_FL_PULLUP);
si->gpio->set(si->reset_gpio, 0);
#if defined(LWS_PLAT_FREERTOS)
vTaskDelay(10);
#else
usleep(10000);
#endif
si->gpio->set(si->reset_gpio, 1);
#if defined(LWS_PLAT_FREERTOS)
vTaskDelay(1);
#else
usleep(1000);
#endif
}
if (lws_i2c_command_list(si->i2c, si->i2c7_address,
ssd1306_128x64_init,
LWS_ARRAY_SIZE(ssd1306_128x64_init))) {
lwsl_err("%s: fail\n", __func__);
return 1;
}
return 0;
}
int
lws_display_ssd1306_i2c_brightness(const struct lws_display *disp, uint8_t b)
{
const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp;
uint8_t ba[2];
ba[0] = SSD1306_SETCONTRAST;
ba[1] = b;
return lws_i2c_command_list(si->i2c, si->i2c7_address,
ba, LWS_ARRAY_SIZE(ba));
}
int
lws_display_ssd1306_i2c_blit(const struct lws_display *disp, const uint8_t *src,
lws_display_scalar x, lws_display_scalar y,
lws_display_scalar w, lws_display_scalar h)
{
const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp;
uint8_t ba[6];
int n, m;
/*
* The display is arranged in 128x8 bands, with one byte containing
* the 8 vertical pixels of the band.
*/
if (h < 8)
h = 8;
ba[0] = SSD1306_COLUMNADDR;
ba[1] = x;
ba[2] = x + w - 1;
ba[3] = SSD1306_PAGEADDR;
ba[4] = y / 8;
ba[5] = ba[4] + (h / 8) - 1;
if (lws_i2c_command_list(si->i2c, si->i2c7_address,
ba, LWS_ARRAY_SIZE(ba))) {
lwsl_err("%s: fail\n", __func__);
return 1;
}
for (n = 0; n < (w * h) / 8;) {
lws_bb_i2c_start(si->i2c);
lws_bb_i2c_write(si->i2c, si->i2c7_address << 1);
lws_bb_i2c_write(si->i2c, SSD1306_SETSTARTLINE | y);
for (m = 0; m < w; m++)
lws_bb_i2c_write(si->i2c, src[n++]);
lws_bb_i2c_stop(si->i2c);
y += 8;
}
return 0;
}
int
lws_display_ssd1306_i2c_power(const struct lws_display *disp, int state)
{
const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp;
if (!state)
return lws_i2c_command(si->i2c, si->i2c7_address,
SSD1306_DISPLAYOFF | !!state);
return lws_display_ssd1306_i2c_init(disp);
}

View file

@ -0,0 +1,135 @@
/*
* I2C bitbang implementation using generic gpio
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* This is like an abstract class for gpio, a real implementation provides
* functions for the ops that use the underlying OS gpio arrangements.
*/
#include <libwebsockets.h>
int
lws_bb_i2c_init(const lws_i2c_ops_t *octx)
{
lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx;
ctx->gpio->mode(ctx->scl, LWSGGPIO_FL_WRITE | LWSGGPIO_FL_READ | LWSGGPIO_FL_PULLUP);
ctx->gpio->mode(ctx->sda, LWSGGPIO_FL_WRITE | LWSGGPIO_FL_READ | LWSGGPIO_FL_PULLUP);
return 0;
}
int
lws_bb_i2c_start(const lws_i2c_ops_t *octx)
{
lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx;
ctx->gpio->set(ctx->sda, 1);
ctx->gpio->set(ctx->scl, 1);
ctx->delay();
if (!ctx->gpio->read(ctx->sda))
return 1;
ctx->gpio->set(ctx->sda, 0);
ctx->delay();
ctx->gpio->set(ctx->scl, 0);
return 0;
}
void
lws_bb_i2c_stop(const lws_i2c_ops_t *octx)
{
lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx;
ctx->gpio->set(ctx->sda, 0);
ctx->gpio->set(ctx->scl, 1);
ctx->delay();
while (!ctx->gpio->read(ctx->scl))
;
ctx->gpio->set(ctx->sda, 1);
ctx->delay();
}
int
lws_bb_i2c_write(const lws_i2c_ops_t *octx, uint8_t data)
{
lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx;
int n;
for (n = 0; n < 8; n++) {
ctx->gpio->set(ctx->sda, !!(data & (1 << 7)));
ctx->delay();
ctx->gpio->set(ctx->scl, 1);
ctx->delay();
data <<= 1;
ctx->gpio->set(ctx->scl, 0);
}
ctx->gpio->set(ctx->sda, 1);
ctx->delay();
ctx->gpio->set(ctx->scl, 1);
ctx->delay();
n = ctx->gpio->read(ctx->sda);
ctx->gpio->set(ctx->scl, 0);
ctx->delay();
return !!n; /* 0 = ACKED = OK */
}
int
lws_bb_i2c_read(const lws_i2c_ops_t *octx)
{
lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx;
int n, r = 0;
ctx->gpio->set(ctx->sda, 1);
for (n = 7; n <= 0; n--) {
ctx->gpio->set(ctx->scl, 0);
ctx->delay();
ctx->gpio->set(ctx->scl, 1);
ctx->delay();
if (ctx->gpio->read(ctx->sda))
r |= 1 << n;
}
ctx->gpio->set(ctx->scl, 0);
return r;
}
void
lws_bb_i2c_set_ack(const lws_i2c_ops_t *octx, int ack)
{
lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx;
ctx->gpio->set(ctx->scl, 0);
ctx->gpio->set(ctx->sda, !!ack);
ctx->delay();
ctx->gpio->set(ctx->scl, 1);
ctx->delay();
ctx->gpio->set(ctx->scl, 0);
ctx->delay();
ctx->gpio->set(ctx->sda, 1);
}

59
lib/drivers/i2c/lws-i2c.c Normal file
View file

@ -0,0 +1,59 @@
/*
* Generic I2C
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* These are generic helpers made up of calls to the i2c driver ops, so they
* just need implementing once like this and are usable for any i2c underlying
* implementation via the ops.
*/
#include <libwebsockets.h>
int
lws_i2c_command(const lws_i2c_ops_t *ctx, uint8_t ads7, uint8_t c)
{
if (ctx->start(ctx))
return 1;
if (ctx->write(ctx, ads7 << 1)) {
ctx->stop(ctx);
return 1;
}
ctx->write(ctx, 0);
ctx->write(ctx, c);
ctx->stop(ctx);
return 0;
}
int
lws_i2c_command_list(const lws_i2c_ops_t *ctx, uint8_t ads7, const uint8_t *buf,
size_t len)
{
while (len--)
if (lws_i2c_command(ctx, ads7, *buf++))
return 1;
return 0;
}

View file

@ -0,0 +1,96 @@
/*
* esp32 / esp-idf gpio
*
* Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <libwebsockets.h>
static void
lws_gpio_esp32_mode(_lws_plat_gpio_t gpio, int flags)
{
int mode, pup = GPIO_FLOATING;
switch (flags & (LWSGGPIO_FL_READ | LWSGGPIO_FL_WRITE)) {
default:
lwsl_err("%s: neither read nor write\n", __func__);
return;
case LWSGGPIO_FL_READ:
mode = GPIO_MODE_INPUT;
break;
case LWSGGPIO_FL_WRITE:
mode = GPIO_MODE_OUTPUT;
break;
case LWSGGPIO_FL_READ | LWSGGPIO_FL_WRITE:
mode = GPIO_MODE_INPUT_OUTPUT;
break;
}
switch (flags & (LWSGGPIO_FL_PULLUP | LWSGGPIO_FL_PULLDOWN)) {
default:
break;
case LWSGGPIO_FL_PULLUP:
pup = GPIO_PULLUP_ONLY;
break;
case LWSGGPIO_FL_PULLDOWN:
pup = GPIO_PULLDOWN_ONLY;
break;
case LWSGGPIO_FL_PULLUP | LWSGGPIO_FL_PULLDOWN:
pup = GPIO_PULLUP_PULLDOWN;
break;
}
gpio_reset_pin(gpio);
gpio_set_direction(gpio, mode);
gpio_set_pull_mode(gpio, pup);
gpio_set_level(gpio, flags & LWSGGPIO_FL_START_LOW ? 0 : 1);
}
static int
lws_gpio_esp32_read(_lws_plat_gpio_t gpio)
{
return gpio_get_level(gpio);
}
static void
lws_gpio_esp32_set(_lws_plat_gpio_t gpio, int val)
{
gpio_set_level(gpio, val);
}
static int
lws_gpio_esp32_irq_mode(_lws_plat_gpio_t gpio, lws_gpio_irq_t irq_type,
lws_gpio_irq_cb_t cb, void *arg)
{
if (gpio_set_intr_type(gpio, irq_type))
return 1;
if (cb)
return gpio_isr_handler_add(gpio, cb, arg);
return gpio_isr_handler_remove(gpio);
}
const lws_gpio_ops_t lws_gpio_plat = {
.mode = lws_gpio_esp32_mode,
.read = lws_gpio_esp32_read,
.set = lws_gpio_esp32_set,
.irq_mode = lws_gpio_esp32_irq_mode,
};

View file

@ -0,0 +1,25 @@
/*
* lws generic gpio - esp32 platform wrapper
*
* Written in 2010-2020 by Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
extern const lws_gpio_ops_t lws_gpio_plat;

View file

@ -111,5 +111,9 @@ lws_plat_init(struct lws_context *context,
context->set = lws_h2_defaults_esp32;
#endif
#if defined(LWS_ESP_PLATFORM)
gpio_install_isr_service(0);
#endif
return 0;
}

View file

@ -6,6 +6,10 @@ if (ESP_PLATFORM)
enable_testing()
target_link_libraries(lws-minimal-esp32.elf websockets)
option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" ON)
set(LWS_WITH_DRIVERS ON)
add_subdirectory(libwebsockets)
add_test(NAME flashing COMMAND idf.py flash)

View file

@ -0,0 +1,64 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0x40, 0x20, 0x20, 0x20, 0x20, 0x00, 0x40, 0xE0, 0x00, 0x80, 0xE0, 0x20, 0x20,
0x20, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x80, 0x40, 0x20,
0x20, 0x20, 0x60, 0x80, 0x00, 0xE0, 0x40, 0x20, 0x20, 0x60, 0xC0, 0x00, 0x80, 0x40, 0x20, 0x20,
0x20, 0x60, 0x80, 0x00, 0xC0, 0x60, 0x20, 0x20, 0x20, 0xC0, 0x00, 0x80, 0xC0, 0x20, 0x20, 0x20,
0x40, 0xC0, 0x00, 0xE0, 0x00, 0x80, 0x80, 0x60, 0x00, 0x80, 0xC0, 0x20, 0x20, 0x20, 0x60, 0x80,
0x00, 0x00, 0x40, 0x60, 0x20, 0x00, 0xC0, 0x40, 0x20, 0x20, 0x20, 0xC0, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x34, 0x2F, 0x08, 0x08,
0x08, 0x0D, 0x07, 0x00, 0x0F, 0x00, 0x01, 0x0E, 0x0E, 0x01, 0x00, 0x0F, 0x08, 0x02, 0x0F, 0x09,
0x09, 0x19, 0x0F, 0x02, 0x00, 0x7F, 0x19, 0x08, 0x18, 0x08, 0x07, 0x01, 0x00, 0x0E, 0x09, 0x0B,
0x09, 0x0D, 0x04, 0x00, 0x07, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x00, 0x03, 0x0E, 0x08, 0x18, 0x08,
0x0C, 0x04, 0x00, 0x7F, 0x02, 0x07, 0x08, 0x08, 0x00, 0x05, 0x0F, 0x0A, 0x11, 0x09, 0x0D, 0x06,
0x00, 0x08, 0x3F, 0x19, 0x08, 0x00, 0x06, 0x0A, 0x09, 0x09, 0x09, 0x0D, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xC0,
0xE0, 0xE0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xE0,
0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC1, 0x87, 0x8F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x00, 0x00,
0x00, 0x80, 0x80, 0xC0, 0x83, 0x87, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x83, 0x80, 0x80, 0x80, 0x83,
0x07, 0x0F, 0x1F, 0x0F, 0x0F, 0x0F, 0x83, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F,
0x0F, 0x0F, 0x0F, 0x8F, 0x87, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x00, 0xBC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xF8, 0x00, 0x28, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00,
0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F,
0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F, 0x3F, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0x7F, 0x7F,
0x3F, 0x0E, 0x00, 0x05, 0x3F, 0x7F, 0x7F, 0xFF, 0x7F, 0x7F, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0E, 0x3F, 0x7F, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

View file

@ -21,16 +21,50 @@
#include "esp_wifi.h"
#include <nvs_flash.h>
#include <esp_netif.h>
#include <driver/gpio.h>
#include <libwebsockets.h>
struct lws_context *context;
lws_sorted_usec_list_t sul;
lws_display_state_t lds;
int interrupted;
static void
esp32_i2c_delay(void)
{
ets_delay_us(1);
}
static const lws_bb_i2c_t li2c = {
.bb_ops = lws_bb_i2c_ops,
.scl = GPIO_NUM_15,
.sda = GPIO_NUM_4,
.gpio = &lws_gpio_plat,
.delay = esp32_i2c_delay
};
static const lws_display_ssd1306_t disp = {
.disp = {
lws_display_ssd1306_ops,
.w = 128,
.h = 64
},
.i2c = (lws_i2c_ops_t *)&li2c,
.gpio = &lws_gpio_plat,
.reset_gpio = GPIO_NUM_16,
.i2c7_address = SSD1306_I2C7_ADS1
};
static const uint8_t img[] = {
#include "../banded-img.h"
};
static void
sul_cb(lws_sorted_usec_list_t *sul)
{
interrupted = 1;
//interrupted = 1;
lwsl_notice("Completed: PASS\n");
}
void
@ -38,8 +72,6 @@ app_main(void)
{
wifi_init_config_t wic = WIFI_INIT_CONFIG_DEFAULT();
struct lws_context_creation_info info;
struct lws_context *context;
esp_chip_info_t chip_info;
int n = 0;
lws_set_log_level(15, NULL);
@ -54,20 +86,7 @@ app_main(void)
memset(&info, 0, sizeof(info));
lwsl_notice("LWS minimal build test\n");
esp_chip_info(&chip_info);
lwsl_notice("chip: %s (%d CPU cores) WiFi%s%s\n",
CONFIG_IDF_TARGET, chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
lwsl_notice("silicon revision %d\n", chip_info.revision);
lwsl_notice("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
lwsl_notice("Free heap: %d\n", esp_get_free_heap_size());
lwsl_notice("LWS test for Heltec WB32 ESP32 board\n");
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
info.port = CONTEXT_PORT_NO_LISTEN;
@ -78,7 +97,15 @@ app_main(void)
}
/*
* We just exit the event loop after 3s
* Show the lws logo on the display
*/
lws_display_state_init(&lds, context, 10000, 20000, 200, 10, &disp.disp);
lws_display_state_active(&lds);
disp.disp.blit(lds.disp, img, 0, 0, 128, 64);
/*
* We say the test succeeded if we survive 3s around the event loop
*/
lws_sul_schedule(context, 0, &sul, sul_cb, 3 * LWS_USEC_PER_SEC);
@ -90,7 +117,6 @@ app_main(void)
lws_context_destroy(context);
lwsl_notice("Completed: PASS\n");
// fflush(stdout);
// esp_restart();
@ -99,4 +125,3 @@ spin:
taskYIELD();
goto spin;
}

Binary file not shown.

After

(image error) Size: 1.1 KiB

View file

@ -0,0 +1,64 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x2f, 0x27, 0xc6, 0x61, 0xe5, 0xc3, 0xc7, 0x87, 0x11, 0x1e, 0x18, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x30, 0x64, 0x46, 0x62, 0x26, 0x64, 0x4c, 0x48, 0xd1, 0x22, 0x33, 0x18, 0x00, 0x00,
0x00, 0x00, 0x20, 0x2c, 0x46, 0x64, 0x14, 0x28, 0x28, 0x58, 0x56, 0x61, 0x02, 0x10, 0x00, 0x00,
0x00, 0x00, 0x20, 0x24, 0x6a, 0x53, 0xe6, 0x33, 0xc8, 0x50, 0x14, 0x6e, 0x30, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x20, 0x24, 0x29, 0x96, 0x34, 0x25, 0x08, 0x58, 0x1c, 0x31, 0x23, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x6c, 0x69, 0x92, 0x24, 0x24, 0x68, 0x48, 0xd4, 0x63, 0x22, 0x10, 0x00, 0x00,
0x00, 0x00, 0x20, 0x27, 0xc9, 0x9b, 0xe7, 0xc7, 0xc7, 0xcf, 0x93, 0x36, 0x79, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x46, 0x80, 0x00, 0x02, 0x10, 0x08, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0x2c, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x20, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x30, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x07, 0xe0, 0xfc, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x07, 0xe0, 0xfc, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x7c, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x7c, 0x1f, 0x03, 0xc0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xff, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x9f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x78, 0x1f, 0x07, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x04, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

View file

@ -0,0 +1,64 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x2f, 0x27, 0xc6, 0x61, 0xe5, 0xc3, 0xc7, 0x87, 0x11, 0x1e, 0x18, 0xe0, 0x00, 0x00
0x00, 0x00, 0x30, 0x64, 0x46, 0x62, 0x26, 0x64, 0x4c, 0x48, 0xd1, 0x22, 0x33, 0x18, 0x00, 0x00
0x00, 0x00, 0x20, 0x2c, 0x46, 0x64, 0x14, 0x28, 0x28, 0x58, 0x56, 0x61, 0x02, 0x10, 0x00, 0x00
0x00, 0x00, 0x20, 0x24, 0x6a, 0x53, 0xe6, 0x33, 0xc8, 0x50, 0x14, 0x6e, 0x30, 0xf0, 0x00, 0x00
0x00, 0x00, 0x20, 0x24, 0x29, 0x96, 0x34, 0x25, 0x08, 0x58, 0x1c, 0x31, 0x23, 0x00, 0x00, 0x00
0x00, 0x00, 0x30, 0x6c, 0x69, 0x92, 0x24, 0x24, 0x68, 0x48, 0xd4, 0x63, 0x22, 0x10, 0x00, 0x00
0x00, 0x00, 0x20, 0x27, 0xc9, 0x9b, 0xe7, 0xc7, 0xc7, 0xcf, 0x93, 0x36, 0x79, 0xf0, 0x00, 0x00
0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x46, 0x80, 0x00, 0x02, 0x10, 0x08, 0x30, 0x00, 0x00, 0x00
0x00, 0x00, 0x20, 0x2c, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x00, 0x00
0x00, 0x00, 0x20, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x30, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x07, 0xe0, 0xfc, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x03, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x07, 0xe0, 0xfc, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x7c, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x7c, 0x1f, 0x03, 0xc0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xff, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x9f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x78, 0x1f, 0x07, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x04, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

Binary file not shown.

View file

@ -0,0 +1,70 @@
#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");
}
}

View file

@ -0,0 +1,8 @@
#!/bin/bash
convert -size 128x64 /tmp/128x64.png -monochrome output.bmp
dd if=output.bmp bs=1 skip=130 | hexdump -Cv | tr -s ' ' | cut -d' ' -f2-17 | grep ' ' | sed "s/^/0x/g" | sed "s/\ /,\ 0x/g" > pic.h.1
cat pic.h.1 | sed "s/\$/,/g" > pic.h
gcc -o scan scan.c && ./scan > ../banded-img.h