nrf5/drivers: Adding SSD1306 SPI display driver. Not complete, but can do fill screen operation atm.
This commit is contained in:
parent
1d2bf26373
commit
073cfc0a2e
|
@ -154,6 +154,8 @@ DRIVERS_SRC_C += $(addprefix drivers/,\
|
|||
display/epaper_sld00200p_driver.c \
|
||||
display/lcd_ili9341_obj.c \
|
||||
display/lcd_ili9341_driver.c \
|
||||
display/oled_ssd1306_obj.c \
|
||||
display/oled_ssd1306_driver.c \
|
||||
)
|
||||
|
||||
#ifeq ($(SD), )
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "epaper_sld00200p_obj.h"
|
||||
#include "lcd_ili9341_obj.h"
|
||||
#include "oled_ssd1306_obj.h"
|
||||
|
||||
STATIC const mp_map_elem_t mp_module_display_globals_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_display) },
|
||||
|
@ -39,11 +40,13 @@ STATIC const mp_map_elem_t mp_module_display_globals_table[] = {
|
|||
#if MICROPY_PY_DISPLAY_LCD_ILI9341
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ILI9341), (mp_obj_t)&lcd_ili9341_type },
|
||||
#endif
|
||||
#if MICROPY_PY_DISPLAY_OLED_SSD1306
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SSD1306), (mp_obj_t)&oled_ssd1306_type },
|
||||
#endif
|
||||
#if 0
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SSD1289), (mp_obj_t)&lcd_ssd1289_type },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LS027b7DH01), (mp_obj_t)&lcd_ls027b7dh01_type },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SSD1305), (mp_obj_t)&oled_ssd1305_type },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_SSD1306), (mp_obj_t)&oled_ssd1306_type },
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Glenn Ruben Bakke
|
||||
*
|
||||
* 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 <stdbool.h>
|
||||
|
||||
#include "py/mphal.h"
|
||||
|
||||
#include "oled_ssd1306_driver.h"
|
||||
#include "hal_spi.h"
|
||||
#include "hal_time.h"
|
||||
|
||||
#if MICROPY_PY_DISPLAY_OLED_SSD1306
|
||||
|
||||
static pin_obj_t * mp_cs_pin;
|
||||
static pin_obj_t * mp_dc_pin;
|
||||
static pin_obj_t * mp_reset_pin;
|
||||
static NRF_SPI_Type * mp_instance;
|
||||
|
||||
|
||||
static void raw_write(uint8_t value)
|
||||
{
|
||||
hal_spi_master_tx_rx(mp_instance, 1, &value, NULL);
|
||||
|
||||
}
|
||||
|
||||
static void cmd_write(uint8_t value)
|
||||
{
|
||||
mp_hal_pin_low(mp_dc_pin);
|
||||
mp_hal_pin_low(mp_cs_pin);
|
||||
|
||||
hal_spi_master_tx_rx(mp_instance, 1, &value, NULL);
|
||||
|
||||
mp_hal_pin_high(mp_cs_pin);
|
||||
}
|
||||
|
||||
#define SET_CONTRAST (0x81)
|
||||
#define SET_ENTIRE_ON (0xa4)
|
||||
#define SET_NORM_INV (0xa6)
|
||||
#define SET_DISP (0xae)
|
||||
#define SET_MEM_ADDR (0x20)
|
||||
#define SET_COL_ADDR (0x21)
|
||||
#define SET_PAGE_ADDR (0x22)
|
||||
#define SET_DISP_START_LINE (0x40)
|
||||
#define SET_SEG_REMAP (0xa0)
|
||||
#define SET_MUX_RATIO (0xa8)
|
||||
#define SET_COM_OUT_DIR (0xc0)
|
||||
#define SET_DISP_OFFSET (0xd3)
|
||||
#define SET_COM_PIN_CFG (0xda)
|
||||
#define SET_DISP_CLK_DIV (0xd5)
|
||||
#define SET_PRECHARGE (0xd9)
|
||||
#define SET_VCOM_DESEL (0xdb)
|
||||
#define SET_CHARGE_PUMP (0x8d)
|
||||
|
||||
void driver_ssd1306_init(NRF_SPI_Type * p_instance, pin_obj_t * p_cs_pin, pin_obj_t * p_dc_pin, pin_obj_t * p_reset_pin)
|
||||
{
|
||||
mp_instance = p_instance;
|
||||
mp_cs_pin = p_cs_pin;
|
||||
mp_dc_pin = p_dc_pin;
|
||||
mp_reset_pin = p_reset_pin;
|
||||
|
||||
mp_hal_pin_high(mp_cs_pin);
|
||||
mp_hal_pin_high(mp_dc_pin);
|
||||
mp_hal_pin_high(mp_reset_pin);
|
||||
|
||||
// power on display
|
||||
mp_hal_pin_high(mp_reset_pin);
|
||||
mp_hal_delay_ms(1);
|
||||
mp_hal_pin_low(mp_reset_pin);
|
||||
mp_hal_delay_ms(10);
|
||||
mp_hal_pin_high(mp_reset_pin);
|
||||
|
||||
// Turn off
|
||||
cmd_write(SET_DISP | 0x00); // off
|
||||
|
||||
// address setting
|
||||
cmd_write(SET_MEM_ADDR);
|
||||
cmd_write(0x00); // horizontal
|
||||
|
||||
// resolution and layout
|
||||
cmd_write(SET_DISP_START_LINE | 0x00);
|
||||
cmd_write(SET_SEG_REMAP | 0x01); // column addr 127 mapped to SEG0
|
||||
cmd_write(SET_MUX_RATIO);
|
||||
|
||||
uint16_t height = 64; // TODO: configurable
|
||||
cmd_write(height - 1); // height - 1
|
||||
cmd_write(SET_COM_OUT_DIR | 0x08); // scan from COM[N] to COM0
|
||||
cmd_write(SET_DISP_OFFSET);
|
||||
cmd_write(0x00);
|
||||
cmd_write(SET_COM_PIN_CFG);
|
||||
if (height == 32) {
|
||||
cmd_write(0x02);
|
||||
} else {
|
||||
cmd_write(0x12);
|
||||
}
|
||||
// timing and driving scheme
|
||||
cmd_write(SET_DISP_CLK_DIV);
|
||||
cmd_write(0x80);
|
||||
cmd_write(SET_PRECHARGE);
|
||||
bool external_vcc = false;
|
||||
if (external_vcc == true) {
|
||||
cmd_write(0x22);
|
||||
} else {
|
||||
cmd_write(0xf1);
|
||||
}
|
||||
cmd_write(SET_VCOM_DESEL);
|
||||
cmd_write(0x30); // 0.83*Vcc
|
||||
// display
|
||||
cmd_write(SET_CONTRAST);
|
||||
cmd_write(0xff); // maximum
|
||||
cmd_write(SET_ENTIRE_ON); // output follows RAM contents
|
||||
cmd_write(SET_NORM_INV); // not inverted
|
||||
// charge pump
|
||||
cmd_write(SET_CHARGE_PUMP);
|
||||
if (external_vcc == true) {
|
||||
cmd_write(0x10);
|
||||
} else {
|
||||
cmd_write(0x14);
|
||||
}
|
||||
// on
|
||||
cmd_write(SET_DISP | 0x01);
|
||||
|
||||
}
|
||||
|
||||
static void set_col(uint16_t start_col, uint16_t end_col)
|
||||
{
|
||||
cmd_write(SET_COL_ADDR); /* Column Command address */
|
||||
cmd_write(start_col & 0xFF );
|
||||
cmd_write(end_col & 0xFF);
|
||||
}
|
||||
|
||||
static void set_page(uint16_t start_page, uint16_t end_page)
|
||||
{
|
||||
cmd_write(SET_PAGE_ADDR); /* Column Command address */
|
||||
cmd_write(start_page & 0xFF);
|
||||
cmd_write(end_page & 0xFF);
|
||||
}
|
||||
|
||||
void driver_ssd1306_clear(uint16_t color)
|
||||
{
|
||||
uint16_t width = 128;
|
||||
uint16_t height = 64;
|
||||
|
||||
uint16_t x0 = 0;
|
||||
uint16_t x1 = width - 1;
|
||||
uint16_t y0 = 0;
|
||||
uint16_t y1 = height -1;
|
||||
|
||||
if (width == 64) {
|
||||
// displays with width of 64 pixels are shifted by 32
|
||||
x0 += 32;
|
||||
x1 += 32;
|
||||
}
|
||||
|
||||
uint16_t num_of_pages = height / 8;
|
||||
set_col(x0, x1);
|
||||
set_page(y0, y1);
|
||||
|
||||
mp_hal_pin_high(mp_dc_pin);
|
||||
mp_hal_pin_low(mp_cs_pin);
|
||||
|
||||
for (uint16_t i = 0; i < (width * num_of_pages); i++) {
|
||||
raw_write(color);
|
||||
}
|
||||
|
||||
mp_hal_pin_high(mp_cs_pin);
|
||||
}
|
||||
|
||||
void driver_ssd1306_update_line(uint16_t line, fb_byte_t * p_bytes, uint16_t len, bool compressed) {
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Glenn Ruben Bakke
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OLED_SSD1306_DRIVER_H__
|
||||
#define OLED_SSD1306_DRIVER_H__
|
||||
|
||||
#include "py/mphal.h"
|
||||
|
||||
#include "hal_spi.h"
|
||||
#include "lcd_mono_fb.h"
|
||||
|
||||
void driver_ssd1306_init(NRF_SPI_Type * p_instance, pin_obj_t * cs_pin, pin_obj_t * dc_pin, pin_obj_t * reset_pin);
|
||||
|
||||
void driver_ssd1306_clear(uint16_t color);
|
||||
|
||||
void driver_ssd1306_update_line(uint16_t line, fb_byte_t * p_bytes, uint16_t len, bool compressed);
|
||||
|
||||
#endif // OLED_SSD1306_DRIVER_H__
|
|
@ -0,0 +1,323 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Glenn Ruben Bakke
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "genhdr/pins.h"
|
||||
|
||||
#include "oled_ssd1306_driver.h"
|
||||
|
||||
#if MICROPY_PY_DISPLAY_OLED_SSD1306
|
||||
|
||||
/// \moduleref display
|
||||
/// \class SSD1306 - SSD1306 TFT LCD display driver.
|
||||
|
||||
#include "pin.h"
|
||||
#include "spi.h"
|
||||
#include "lcd_mono_fb.h"
|
||||
|
||||
typedef struct _oled_ssd1306_obj_t {
|
||||
mp_obj_base_t base;
|
||||
machine_hard_spi_obj_t *spi;
|
||||
pin_obj_t * pin_cs;
|
||||
pin_obj_t * pin_dc;
|
||||
pin_obj_t * pin_reset;
|
||||
mp_obj_framebuf_t * framebuffer;
|
||||
} oled_ssd1306_obj_t;
|
||||
|
||||
static void dirty_line_update_cb(mp_obj_framebuf_t * p_framebuffer,
|
||||
uint16_t line,
|
||||
fb_byte_t * p_new,
|
||||
fb_byte_t * p_old) {
|
||||
// the lcd does not have double buffer needs, skip it.
|
||||
(void)p_old;
|
||||
|
||||
driver_ssd1306_update_line(line, p_new, p_framebuffer->bytes_stride, true);
|
||||
}
|
||||
|
||||
/// \method __str__()
|
||||
/// Return a string describing the SSD1306 object.
|
||||
STATIC void oled_ssd1306_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
oled_ssd1306_obj_t *self = o;
|
||||
|
||||
mp_printf(print, "SSD1306(SPI(mosi=(port=%u, pin=%u), miso=(port=%u, pin=%u), clk=(port=%u, pin=%u)),\n",
|
||||
self->spi->pyb->spi->init.mosi_pin_port,
|
||||
self->spi->pyb->spi->init.mosi_pin,
|
||||
self->spi->pyb->spi->init.miso_pin_port,
|
||||
self->spi->pyb->spi->init.miso_pin,
|
||||
self->spi->pyb->spi->init.clk_pin_port,
|
||||
self->spi->pyb->spi->init.clk_pin
|
||||
);
|
||||
|
||||
mp_printf(print, " cs=(port=%u, pin=%u), dc=(port=%u, pin=%u), reset=(port=%u, pin=%u),\n",
|
||||
self->pin_cs->port,
|
||||
self->pin_cs->pin,
|
||||
self->pin_dc->port,
|
||||
self->pin_dc->pin,
|
||||
self->pin_reset->port,
|
||||
self->pin_reset->pin);
|
||||
|
||||
mp_printf(print, " FB(width=%u, height=%u, dir=%u))\n",
|
||||
self->framebuffer->width,
|
||||
self->framebuffer->height);
|
||||
}
|
||||
|
||||
// for make_new
|
||||
enum {
|
||||
ARG_NEW_WIDTH,
|
||||
ARG_NEW_HEIGHT,
|
||||
ARG_NEW_SPI,
|
||||
ARG_NEW_CS,
|
||||
ARG_NEW_DC,
|
||||
ARG_NEW_RESET
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Example for nrf52832 / pca10040:
|
||||
|
||||
from machine import Pin, SPI
|
||||
from display import SSD1306
|
||||
cs = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
reset = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
dc = Pin("A11", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
spi = SPI(0, baudrate=4000000)
|
||||
d = SSD1306(128, 64, spi, cs, dc, reset)
|
||||
d.text("Hello World!", 32, 32)
|
||||
d.show()
|
||||
|
||||
Example for nrf52840 / pca10056:
|
||||
|
||||
from machine import Pin, SPI
|
||||
from display import SSD1306
|
||||
cs = Pin("B3", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
reset = Pin("B2", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
dc = Pin("B1", mode=Pin.OUT, pull=Pin.PULL_UP)
|
||||
spi = SPI(0, baudrate=8000000)
|
||||
d = SSD1306(128, 64, spi, cs, dc, reset)
|
||||
d.text("Hello World!", 32, 32)
|
||||
d.show()
|
||||
|
||||
*/
|
||||
STATIC mp_obj_t oled_ssd1306_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ ARG_NEW_WIDTH, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ ARG_NEW_HEIGHT, MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
{ ARG_NEW_SPI, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ ARG_NEW_CS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ ARG_NEW_DC, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ ARG_NEW_RESET, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
};
|
||||
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
oled_ssd1306_obj_t *s = m_new_obj_with_finaliser(oled_ssd1306_obj_t);
|
||||
s->base.type = type;
|
||||
|
||||
mp_int_t width;
|
||||
mp_int_t height;
|
||||
|
||||
if (args[ARG_NEW_WIDTH].u_int > 0) {
|
||||
width = args[ARG_NEW_WIDTH].u_int;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Display width not set"));
|
||||
}
|
||||
|
||||
if (args[ARG_NEW_HEIGHT].u_int > 0) {
|
||||
height = args[ARG_NEW_HEIGHT].u_int;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Display height not set"));
|
||||
}
|
||||
|
||||
if (args[ARG_NEW_SPI].u_obj != MP_OBJ_NULL) {
|
||||
s->spi = args[ARG_NEW_SPI].u_obj;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Display SPI not set"));
|
||||
}
|
||||
|
||||
if (args[ARG_NEW_CS].u_obj != MP_OBJ_NULL) {
|
||||
s->pin_cs = args[ARG_NEW_CS].u_obj;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Display CS Pin not set"));
|
||||
}
|
||||
|
||||
if (args[ARG_NEW_DC].u_obj != MP_OBJ_NULL) {
|
||||
s->pin_dc = args[ARG_NEW_DC].u_obj;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Display DC Pin not set"));
|
||||
}
|
||||
|
||||
if (args[ARG_NEW_RESET].u_obj != MP_OBJ_NULL) {
|
||||
s->pin_reset = args[ARG_NEW_RESET].u_obj;
|
||||
} else {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
|
||||
"Display Reset Pin not set"));
|
||||
}
|
||||
|
||||
// direction arg not yet configurable
|
||||
mp_int_t vertical = true;
|
||||
s->framebuffer = lcd_mono_fb_helper_make_new(width, height, vertical);
|
||||
|
||||
driver_ssd1306_init(s->spi->pyb->spi->instance, s->pin_cs, s->pin_dc, s->pin_reset);
|
||||
// Default to black background
|
||||
driver_ssd1306_clear(0);
|
||||
|
||||
// display_clear_screen(s->framebuffer, 0x0);
|
||||
|
||||
return MP_OBJ_FROM_PTR(s);
|
||||
}
|
||||
|
||||
// text
|
||||
|
||||
/// \method fill(color)
|
||||
/// Fill framebuffer with the color defined as argument.
|
||||
STATIC mp_obj_t oled_ssd1306_fill(mp_obj_t self_in, mp_obj_t color) {
|
||||
oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
driver_ssd1306_clear((uint8_t)mp_obj_get_int(color));
|
||||
|
||||
display_clear_screen(self->framebuffer, (uint8_t)mp_obj_get_int(color));
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(oled_ssd1306_fill_obj, oled_ssd1306_fill);
|
||||
|
||||
/// \method show()
|
||||
/// Display content in framebuffer.
|
||||
STATIC mp_obj_t oled_ssd1306_show(size_t n_args, const mp_obj_t *args) {
|
||||
oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
|
||||
display_update(self->framebuffer, false, dirty_line_update_cb);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1306_show_obj, 1, 2, oled_ssd1306_show);
|
||||
|
||||
/// \method refresh([num_of_refresh])
|
||||
/// Refresh content in framebuffer.
|
||||
///
|
||||
/// - With no argument, 1 refresh will be done.
|
||||
/// - With `num_of_refresh` given, The whole framebuffer will be considered
|
||||
/// dirty and will be refreshed the given number of times.
|
||||
STATIC mp_obj_t oled_ssd1306_refresh(mp_obj_t self_in) {
|
||||
oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
(void)self;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(oled_ssd1306_refresh_obj, oled_ssd1306_refresh);
|
||||
|
||||
/// \method pixel(x, y, [color])
|
||||
/// Write one pixel in framebuffer.
|
||||
///
|
||||
/// - With no argument, the color of the pixel in framebuffer will be returend.
|
||||
/// - With `color` given, sets the pixel to the color given.
|
||||
STATIC mp_obj_t oled_ssd1306_pixel(size_t n_args, const mp_obj_t *args) {
|
||||
oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_int_t color;
|
||||
if (n_args >= 3) {
|
||||
color = mp_obj_get_int(args[3]);
|
||||
}
|
||||
(void)self;
|
||||
(void)x;
|
||||
(void)y;
|
||||
(void)color;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1306_pixel_obj, 3, 4, oled_ssd1306_pixel);
|
||||
|
||||
/// \method pixel(text, x, y, [color])
|
||||
/// Write one pixel in framebuffer.
|
||||
///
|
||||
/// - With no argument, the color will be the opposite of background (fill color).
|
||||
/// - With `color` given, sets the pixel to the color given.
|
||||
STATIC mp_obj_t oled_ssd1306_text(size_t n_args, const mp_obj_t *args) {
|
||||
oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
const char *str = mp_obj_str_get_str(args[1]);
|
||||
mp_int_t x = mp_obj_get_int(args[2]);
|
||||
mp_int_t y = mp_obj_get_int(args[3]);
|
||||
mp_int_t color;
|
||||
if (n_args >= 4) {
|
||||
color = mp_obj_get_int(args[3]);
|
||||
}
|
||||
|
||||
display_print_string(self->framebuffer, x, y, str);
|
||||
|
||||
(void)color;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1306_text_obj, 4, 5, oled_ssd1306_text);
|
||||
|
||||
STATIC mp_obj_t oled_ssd1306_del(mp_obj_t self_in) {
|
||||
oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
(void)self;
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(oled_ssd1306_del_obj, oled_ssd1306_del);
|
||||
|
||||
STATIC const mp_map_elem_t oled_ssd1306_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)(&oled_ssd1306_del_obj) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_fill), (mp_obj_t)(&oled_ssd1306_fill_obj) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)(&oled_ssd1306_show_obj) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)(&oled_ssd1306_text_obj) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_pixel), (mp_obj_t)(&oled_ssd1306_pixel_obj) },
|
||||
#if 0
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitmap), (mp_obj_t)(&oled_ssd1306_bitmap_obj) },
|
||||
#endif
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(LCD_BLACK) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(LCD_WHITE) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_VERTICAL), MP_OBJ_NEW_SMALL_INT(0) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HORIZONTAL), MP_OBJ_NEW_SMALL_INT(1) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(oled_ssd1306_locals_dict, oled_ssd1306_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t oled_ssd1306_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SSD1306,
|
||||
.print = oled_ssd1306_print,
|
||||
.make_new = oled_ssd1306_make_new,
|
||||
.locals_dict = (mp_obj_t)&oled_ssd1306_locals_dict
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_DISPLAY_OLED_SSD1306
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Glenn Ruben Bakke
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OLED_SSD1306_H__
|
||||
#define OLED_SSD1306_H__
|
||||
|
||||
#include <py/obj.h>
|
||||
|
||||
extern const mp_obj_type_t oled_ssd1306_type;
|
||||
|
||||
#endif // OLED_SSD1306_H__
|
||||
|
Loading…
Reference in New Issue