/** * \brief Initialize ST7565R controller and LCD display. * It will also write the graphic controller RAM to all zeroes. * * \note This function will clear the contents of the display. */ void gfx_mono_st7565r_init(void) { uint8_t page; uint8_t column; #ifdef CONFIG_ST7565R_FRAMEBUFFER gfx_mono_set_framebuffer(framebuffer); #endif /* Initialize the low-level display controller. */ st7565r_init(); /* Set display to output data from line 0 */ st7565r_set_display_start_line_address(0); /* Clear the contents of the display. * If using a framebuffer (SPI interface) it will both clear the * controller memory and the framebuffer. */ for (page = 0; page < GFX_MONO_LCD_PAGES; page++) { for (column = 0; column < GFX_MONO_LCD_WIDTH; column++) { gfx_mono_put_byte(page, column, 0x00); } } }
/** * \brief Draw pixel to screen * * \param x X coordinate of the pixel * \param y Y coordinate of the pixel * \param color Pixel operation * * The following will set the pixel at x=10,y=10: * \code * gfx_mono_ssd1306_draw_pixel(10, 10, GFX_PIXEL_SET); * \endcode * The following example will clear the pixel at x=10,y=10: * \code * gfx_mono_ssd1306_draw_pixel(10, 10, GFX_PIXEL_CLR); * \endcode * And the following will toggle the pixel at x=10,y=10: * \code * gfx_mono_ssd1306_draw_pixel(10, 10, GFX_PIXEL_XOR); * \endcode */ void gfx_mono_ssd1306_draw_pixel(gfx_coord_t x, gfx_coord_t y, gfx_coord_t color) { uint8_t page; uint8_t pixel_mask; uint8_t pixel_value; /* Discard pixels drawn outside the screen */ if ((x > GFX_MONO_LCD_WIDTH - 1) || (y > GFX_MONO_LCD_HEIGHT - 1)) { return; } page = y / GFX_MONO_LCD_PIXELS_PER_BYTE; pixel_mask = (1 << (y - (page * 8))); /* * Read the page containing the pixel in interest, then perform the * requested action on this pixel before writing the page back to the * display. */ pixel_value = gfx_mono_get_byte(page, x); switch (color) { case GFX_PIXEL_SET: pixel_value |= pixel_mask; break; case GFX_PIXEL_CLR: pixel_value &= ~pixel_mask; break; case GFX_PIXEL_XOR: pixel_value ^= pixel_mask; break; default: break; } gfx_mono_put_byte(page, x, pixel_value); }
/** * \brief Read/Modify/Write a byte in the framebuffer * * This function will read the byte from the framebuffer and * do a mask operation on the byte according to the pixel operation selected * by the color argument and the pixel mask provided. * * \param page Page address * \param column Page offset (x coordinate) * \param pixel_mask Mask for pixel operation * \param color Pixel operation * * A small example that will XOR the first byte of the framebuffer with 0xAA * \code * gfx_mono_framebuffer_mask_byte(0,0,0xAA,GFX_PIXEL_XOR); * \endcode */ void gfx_mono_framebuffer_mask_byte(gfx_coord_t page, gfx_coord_t column, gfx_mono_color_t pixel_mask, gfx_mono_color_t color) { gfx_mono_color_t temp; temp = gfx_mono_get_byte(page, column); switch(color) { case GFX_PIXEL_SET: temp |= pixel_mask; break; case GFX_PIXEL_CLR: temp &= ~pixel_mask; break; case GFX_PIXEL_XOR: temp ^= pixel_mask; break; } gfx_mono_put_byte(page, column, temp); }