/** * \brief Get the pixel value at x,y * * \param x X coordinate of pixel * \param y Y coordinate of pixel * \return Non zero value if pixel is set. * * The following example will read the pixel value from x=10,y=10: * \code * pixelval = gfx_mono_ssd1306_get_pixel(10,10); * \endcode */ uint8_t gfx_mono_ssd1306_get_pixel(gfx_coord_t x, gfx_coord_t y) { uint8_t page; uint8_t pixel_mask; if ((x > GFX_MONO_LCD_WIDTH - 1) || (y > GFX_MONO_LCD_HEIGHT - 1)) { return 0; } page = y / GFX_MONO_LCD_PIXELS_PER_BYTE; pixel_mask = (1 << (y - (page * 8))); return gfx_mono_get_byte(page, x) & pixel_mask; }
/** * \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); }