Skip to content
Snippets Groups Projects
Select Git revision
  • c3bcca29f279e3105efa7989db80153f5df6e6d1
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
36 results

sys_display.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    sys_display.c 5.83 KiB
    #include "py/obj.h"
    #include "py/objstr.h"
    #include "py/objint.h"
    #include "py/runtime.h"
    
    #include "epicardium.h"
    #include <stdio.h>
    
    static uint16_t rgb888_to_rgb565(uint8_t *bytes)
    {
    	return ((bytes[0] & 0b11111000) << 8) | ((bytes[1] & 0b11111100) << 3) |
    	       (bytes[2] >> 3);
    }
    
    static uint16_t get_color(mp_obj_t color_in)
    {
    	if (mp_obj_get_int(mp_obj_len(color_in)) < 3) {
    		mp_raise_ValueError("color must have 3 elements");
    	}
    
    	uint8_t red = mp_obj_get_int(
    		mp_obj_subscr(color_in, mp_obj_new_int(0), MP_OBJ_SENTINEL)
    	);
    	uint8_t green = mp_obj_get_int(
    		mp_obj_subscr(color_in, mp_obj_new_int(1), MP_OBJ_SENTINEL)
    	);
    	uint8_t blue = mp_obj_get_int(
    		mp_obj_subscr(color_in, mp_obj_new_int(2), MP_OBJ_SENTINEL)
    	);
    	uint8_t colors[3] = { red, green, blue };
    	return rgb888_to_rgb565(colors);
    }
    
    /* print something on the display */
    static mp_obj_t mp_display_print(size_t n_args, const mp_obj_t *args)
    {
    	if (!mp_obj_is_str_or_bytes(args[0])) {
    		mp_raise_TypeError("input text must be a string");
    	}
    	GET_STR_DATA_LEN(args[0], print, print_len);
    	uint32_t posx = mp_obj_get_int(args[1]);
    	uint32_t posy = mp_obj_get_int(args[2]);
    	uint32_t fg   = get_color(args[3]);
    	uint32_t bg   = get_color(args[4]);
    	int res = epic_disp_print(posx, posy, (const char *)print, fg, bg);
    	if (res < 0) {
    		mp_raise_OSError(-res);
    	}
    	return mp_const_none;
    }
    
    /* draw line on the display */
    static mp_obj_t mp_display_line(size_t n_args, const mp_obj_t *args)
    {
    	uint16_t xs  = mp_obj_get_int(args[0]);
    	uint16_t ys  = mp_obj_get_int(args[1]);
    	uint16_t xe  = mp_obj_get_int(args[2]);
    	uint16_t ye  = mp_obj_get_int(args[3]);
    	uint16_t col = get_color(args[4]);
    	uint16_t ls  = mp_obj_get_int(args[5]);
    	uint16_t ps  = mp_obj_get_int(args[6]);
    
    	//TODO: Move sanity checks to epicardium
    	if (xs > 160 || xs < 0 || xe > 160 || xe < 0) {
    		mp_raise_ValueError("X-Coords have to be 0 < x < 160");
    	}
    
    	if (ys > 80 || ys < 0 || ye > 80 || ye < 0) {
    		mp_raise_ValueError("Y-Coords have to be 0 < x < 80");
    	}