diff --git a/.gitignore b/.gitignore index 0dd8629..cc1a9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ +*.mpy +.idea __pycache__ _build *.pyc .env build* bundles +*.DS_Store +.eggs +dist +**/*.egg-info diff --git a/adafruit_ra8875/ra8875.py b/adafruit_ra8875/ra8875.py index a36c87a..fbad93a 100755 --- a/adafruit_ra8875/ra8875.py +++ b/adafruit_ra8875/ra8875.py @@ -67,7 +67,7 @@ def color565(r, g=0, b=0): return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3 #pylint: enable-msg=invalid-name -class RA8875_Device(object): +class RA8875_Device(): """ Base Class for the Display. Contains all the low level stuff. As well as the touch functions. Valid display sizes are currently 800x480 and 480x272. @@ -87,15 +87,19 @@ def __init__(self, spi, cs, rst=None, width=800, height=480, """ self.spi_device = spi_device.SPIDevice(spi, cs, baudrate=baudrate, polarity=polarity, phase=phase) + # Display advertised as 480x80 is actually 480x82 + if width == 480 and height == 80: + height = 82 self.width = width self.height = height self._mode = None self._tpin = None self.rst = rst + self.vert_offset = 0 if self.rst: self.rst.switch_to_output(value=0) self.reset() - if self.read_reg(0) == 0x75: + if self._read_reg(0) == 0x75: return self._adc_clk = reg.TPCR0_ADCCLK_DIV16 #pylint: enable-msg=invalid-name,too-many-arguments @@ -106,6 +110,9 @@ def init(self, start_on=True): :param bool start_on: (optional) If the display should start in an On State (default=True) """ + if self.width == 480 and self.height == 82: + self.vert_offset = 190 + if self.width == 800 and self.height == 480: pixclk = reg.PCSR_PDATL | reg.PCSR_2CLK hsync_nondisp = 26 @@ -114,7 +121,7 @@ def init(self, start_on=True): vsync_nondisp = 32 vsync_start = 23 vsync_pw = 2 - elif self.width == 480 and (self.height == 272 or self.height == 128): + elif self.width == 480 and (self.height == 272 or self.height == 128 or self.height == 82): pixclk = reg.PCSR_PDATL | reg.PCSR_4CLK hsync_nondisp = 10 hsync_start = 8 @@ -128,40 +135,33 @@ def init(self, start_on=True): self.pllinit() - self.write_reg(reg.SYSR, reg.SYSR_16BPP | reg.SYSR_MCU8) - self.write_reg(reg.PCSR, pixclk) + self._write_reg(reg.SYSR, reg.SYSR_16BPP | reg.SYSR_MCU8) + self._write_reg(reg.PCSR, pixclk) time.sleep(0.001) # Horizontal settings registers - self.write_reg(reg.HDWR, self.width // 8 - 1) - self.write_reg(reg.HNDFTR, reg.HNDFTR_DE_HIGH) - self.write_reg(reg.HNDR, (hsync_nondisp - 2) // 8) - self.write_reg(reg.HSTR, hsync_start // 8 - 1) - self.write_reg(reg.HPWR, reg.HPWR_LOW + hsync_pw // 8 - 1) + self._write_reg(reg.HDWR, self.width // 8 - 1) + self._write_reg(reg.HNDFTR, reg.HNDFTR_DE_HIGH) + self._write_reg(reg.HNDR, (hsync_nondisp - 2) // 8) + self._write_reg(reg.HSTR, hsync_start // 8 - 1) + self._write_reg(reg.HPWR, reg.HPWR_LOW + hsync_pw // 8 - 1) # Vertical settings registers - self.write_reg(reg.VDHR0, (self.height - 1) & 0xFF) - self.write_reg(reg.VDHR1, (self.height - 1) >> 8) - self.write_reg(reg.VNDR0, vsync_nondisp - 1) - self.write_reg(reg.VNDR1, vsync_nondisp >> 8) - self.write_reg(reg.VSTR0, vsync_start - 1) - self.write_reg(reg.VSTR1, vsync_start >> 8) - self.write_reg(reg.VPWR, reg.VPWR_LOW + vsync_pw - 1) + self._write_reg16(reg.VDHR0, self.height - 1 + self.vert_offset) + self._write_reg16(reg.VNDR0, vsync_nondisp - 1) + self._write_reg16(reg.VSTR0, vsync_start - 1) + self._write_reg(reg.VPWR, reg.VPWR_LOW + vsync_pw - 1) # Set active window X - self.write_reg(reg.HSAW0, 0) - self.write_reg(reg.HSAW1, 0) - self.write_reg(reg.HEAW0, (self.width - 1) & 0xFF) - self.write_reg(reg.HEAW1, (self.width - 1) >> 8) + self._write_reg16(reg.HSAW0, 0) + self._write_reg16(reg.HEAW0, self.width - 1) # Set active window Y - self.write_reg(reg.VSAW0, 0) - self.write_reg(reg.VSAW1, 0) - self.write_reg(reg.VEAW0, (self.height - 1) & 0xFF) - self.write_reg(reg.VEAW1, (self.height - 1) >> 8) + self._write_reg16(reg.VSAW0, self.vert_offset) + self._write_reg16(reg.VEAW0, self.height - 1 + self.vert_offset) # Clear the entire window - self.write_reg(reg.MCLR, reg.MCLR_START | reg.MCLR_FULL) + self._write_reg(reg.MCLR, reg.MCLR_START | reg.MCLR_FULL) time.sleep(0.500) # Turn the display on, enable GPIO, and setup the backlight @@ -172,12 +172,12 @@ def init(self, start_on=True): def pllinit(self): """Init the Controller PLL""" - self.write_reg(reg.PLLC1, reg.PLLC1_PLLDIV1 + 11) + self._write_reg(reg.PLLC1, reg.PLLC1_PLLDIV1 + 11) time.sleep(0.001) - self.write_reg(reg.PLLC2, reg.PLLC2_DIV4) + self._write_reg(reg.PLLC2, reg.PLLC2_DIV4) time.sleep(0.001) - def write_reg(self, cmd, data, raw=False): + def _write_reg(self, cmd, data, raw=False): """ Select a Register and write a byte or push raw data out @@ -186,10 +186,23 @@ def write_reg(self, cmd, data, raw=False): :type data: byte or bytearray :param bool raw: (optional) Is the data a raw bytearray (default=False) """ - self.write_cmd(cmd) - self.write_data(data, raw) + self._write_cmd(cmd) + self._write_data(data, raw) - def write_cmd(self, cmd): + def _write_reg16(self, cmd, data): + """ + Select a Register and write 2 bytes or push raw data out + + :param byte cmd: The register to select + :param data: The byte to write to the register + :type data: byte or bytearray + """ + self._write_cmd(cmd) + self._write_data(data) + self._write_cmd(cmd + 1) + self._write_data(data >> 8) + + def _write_cmd(self, cmd): """ Select a Register/Command @@ -197,9 +210,9 @@ def write_cmd(self, cmd): """ with self.spi_device as spi: spi.write(reg.CMDWR) # pylint: disable=no-member - spi.write(bytearray([cmd])) # pylint: disable=no-member + spi.write(bytearray([cmd & 0xFF])) # pylint: disable=no-member - def write_data(self, data, raw=False): + def _write_data(self, data, raw=False): """ Write a byte or push raw data out @@ -209,9 +222,9 @@ def write_data(self, data, raw=False): """ with self.spi_device as spi: spi.write(reg.DATWR) # pylint: disable=no-member - spi.write(data if raw else bytearray([data])) # pylint: disable=no-member + spi.write(data if raw else bytearray([data & 0xFF])) # pylint: disable=no-member - def read_reg(self, cmd): + def _read_reg(self, cmd): """ Select a Register and read a byte @@ -219,10 +232,11 @@ def read_reg(self, cmd): :return: The results of the register :rtype: byte """ - self.write_cmd(cmd) - return self.read_data() + self._write_cmd(cmd) + return self._read_data() + - def read_data(self): + def _read_data(self): """ Read the data of the previously selected register @@ -235,7 +249,7 @@ def read_data(self): spi.readinto(data) # pylint: disable=no-member return struct.unpack(">B", data)[0] - def wait_poll(self, register, mask): + def _wait_poll(self, register, mask): """ Keep checking a status bit and wait for an operation to complete. After 20ms, a timeout will occur and the function will stop waiting. @@ -248,7 +262,7 @@ def wait_poll(self, register, mask): start = int(round(time.time() * 1000)) while True: time.sleep(0.001) - regval = self.read_reg(register) + regval = self._read_reg(register) if regval & mask == 0: return True millis = int(round(time.time() * 1000)) @@ -261,8 +275,8 @@ def turn_on(self, display_on): :param bool start_on: If the display should turn on or off """ - self.write_reg(reg.PWRR, reg.PWRR_NORMAL | - (reg.PWRR_DISPON if display_on else reg.PWRR_DISPOFF)) + self._write_reg(reg.PWRR, reg.PWRR_NORMAL | + (reg.PWRR_DISPON if display_on else reg.PWRR_DISPOFF)) def reset(self): """Perform a hard reset""" @@ -273,8 +287,8 @@ def reset(self): def soft_reset(self): """Perform a soft reset""" - self.write_reg(reg.PWRR, reg.PWRR_SOFTRESET) - self.write_data(reg.PWRR_NORMAL) + self._write_reg(reg.PWRR, reg.PWRR_SOFTRESET) + self._write_data(reg.PWRR_NORMAL) time.sleep(0.001) def sleep(self, sleep): @@ -283,11 +297,12 @@ def sleep(self, sleep): :param bool sleep: Should we enable sleep mode """ - self.write_reg(reg.PWRR, reg.PWRR_DISPOFF if sleep else (reg.PWRR_DISPOFF | reg.PWRR_SLEEP)) + self._write_reg(reg.PWRR, + reg.PWRR_DISPOFF if sleep else (reg.PWRR_DISPOFF | reg.PWRR_SLEEP)) def _gpiox(self, gpio_on): """Enable or Disable the RA8875 GPIOs""" - self.write_reg(reg.GPIOX, 1 if gpio_on else 0) + self._write_reg(reg.GPIOX, 1 if gpio_on else 0) def _pwm1_config(self, pwm_on, clock): """ @@ -296,7 +311,7 @@ def _pwm1_config(self, pwm_on, clock): :param bool pwm_on: Should we enable the Backlight PWM :param byte clock: Clock Divider to use for PWM Speed """ - self.write_reg(reg.P1CR, (reg.P1CR_ENABLE if pwm_on else reg.P1CR_DISABLE) | (clock & 0xF)) + self._write_reg(reg.P1CR, (reg.P1CR_ENABLE if pwm_on else reg.P1CR_DISABLE) | (clock & 0xF)) def brightness(self, level): """ @@ -304,7 +319,7 @@ def brightness(self, level): :param byte level: The PWM Duty Cycle """ - self.write_reg(reg.P1DCR, level) + self._write_reg(reg.P1DCR, level) def touch_init(self, tpin=None, enable=True): """ @@ -316,7 +331,7 @@ def touch_init(self, tpin=None, enable=True): if tpin is not None: tpin.direction = Direction.INPUT self._tpin = tpin - self.write_reg(reg.INTC2, reg.INTC2_TP) + self._write_reg(reg.INTC2, reg.INTC2_TP) self.touch_enable(enable) def touch_enable(self, touch_on): @@ -326,13 +341,13 @@ def touch_enable(self, touch_on): :param bool touch_on: Enable/Disable the Touch Functionality """ if touch_on: - self.write_reg(reg.TPCR0, reg.TPCR0_ENABLE | reg.TPCR0_WAIT_4096CLK | - reg.TPCR0_WAKEENABLE | self._adc_clk) - self.write_reg(reg.TPCR1, reg.TPCR1_AUTO | reg.TPCR1_DEBOUNCE) - self.write_data(self.read_reg(reg.INTC1) | reg.INTC1_TP) + self._write_reg(reg.TPCR0, reg.TPCR0_ENABLE | reg.TPCR0_WAIT_4096CLK | + reg.TPCR0_WAKEENABLE | self._adc_clk) + self._write_reg(reg.TPCR1, reg.TPCR1_AUTO | reg.TPCR1_DEBOUNCE) + self._write_data(self._read_reg(reg.INTC1) | reg.INTC1_TP) else: - self.write_data(self.read_reg(reg.INTC1) & ~reg.INTC1_TP) - self.write_reg(reg.TPCR0, reg.TPCR0_DISABLE) + self._write_data(self._read_reg(reg.INTC1) & ~reg.INTC1_TP) + self._write_reg(reg.TPCR0, reg.TPCR0_DISABLE) def touched(self): """ @@ -346,7 +361,7 @@ def touched(self): self._gfx_mode() # Hack that seems to work if self._tpin.value: return False - istouched = True if self.read_reg(reg.INTC2) & reg.INTC2_TP else False + istouched = self._read_reg(reg.INTC2) & reg.INTC2_TP return istouched def touch_read(self): @@ -356,29 +371,29 @@ def touch_read(self): :return: The coordinate of the detected touch :rtype: tuple[int, int] """ - touch_x = self.read_reg(reg.TPXH) - touch_y = self.read_reg(reg.TPYH) - temp = self.read_reg(reg.TPXYL) + touch_x = self._read_reg(reg.TPXH) + touch_y = self._read_reg(reg.TPYH) + temp = self._read_reg(reg.TPXYL) touch_x = touch_x << 2 touch_y = touch_y << 2 touch_x |= temp & 0x03 touch_y |= (temp >> 2) & 0x03 - self.write_reg(reg.INTC2, reg.INTC2_TP) + self._write_reg(reg.INTC2, reg.INTC2_TP) return [touch_x, touch_y] def _gfx_mode(self): """Set to Graphics Mode""" if self._mode == "gfx": return - self.write_data(self.read_reg(reg.MWCR0) & ~reg.MWCR0_TXTMODE) + self._write_data(self._read_reg(reg.MWCR0) & ~reg.MWCR0_TXTMODE) self._mode = "gfx" def _txt_mode(self): """Set to Text Mode""" if self._mode == "txt": return - self.write_data(self.read_reg(reg.MWCR0) | reg.MWCR0_TXTMODE) - self.write_data(self.read_reg(reg.FNCR0) & ~((1<<7) | (1<<5))) + self._write_data(self._read_reg(reg.MWCR0) | reg.MWCR0_TXTMODE) + self._write_data(self._read_reg(reg.FNCR0) & ~((1<<7) | (1<<5))) self._mode = "txt" class RA8875Display(RA8875_Device): @@ -411,10 +426,8 @@ def txt_set_cursor(self, x, y): :param int y: The Y coordinate to set the cursor """ self._txt_mode() - self.write_reg(0x2A, x & 0xFF) - self.write_reg(0x2B, x >> 8) - self.write_reg(0x2C, y & 0xFF) - self.write_reg(0x2D, y >> 8) + self._write_reg16(0x2A, x) + self._write_reg16(0x2C, y + self.vert_offset) #pylint: enable-msg=invalid-name def txt_color(self, fgcolor, bgcolor): @@ -426,7 +439,7 @@ def txt_color(self, fgcolor, bgcolor): """ self.set_color(fgcolor) self.set_bgcolor(bgcolor) - self.write_data(self.read_reg(reg.FNCR1) & ~(1<<6)) + self._write_data(self._read_reg(reg.FNCR1) & ~(1<<6)) def txt_trans(self, color): """ @@ -436,7 +449,7 @@ def txt_trans(self, color): """ self._txt_mode() self.set_color(color) - self.write_data(self.read_reg(reg.FNCR1) | 1<<6) + self._write_data(self._read_reg(reg.FNCR1) | 1<<6) def txt_size(self, scale): """ @@ -447,7 +460,7 @@ def txt_size(self, scale): self._txt_mode() if scale > 3: scale = 3 - self.write_data((self.read_reg(reg.FNCR1) & ~(0xF)) | (scale << 2) | scale) + self._write_data((self._read_reg(reg.FNCR1) & ~(0xF)) | (scale << 2) | scale) self._txt_scale = scale def txt_write(self, string): @@ -457,9 +470,9 @@ def txt_write(self, string): :param str string: The text string to write """ self._txt_mode() - self.write_cmd(reg.MRWC) + self._write_cmd(reg.MRWC) for char in string: - self.write_data(char, True) + self._write_data(char, True) if self._txt_scale > 0: time.sleep(0.001) @@ -472,10 +485,8 @@ def setxy(self, x, y): :param int y: The Y coordinate to set the cursor """ self._gfx_mode() - self.write_reg(reg.CURH0, x) - self.write_reg(reg.CURH1, x >> 8) - self.write_reg(reg.CURV0, y) - self.write_reg(reg.CURV1, y >> 8) + self._write_reg16(reg.CURH0, x) + self._write_reg16(reg.CURV0, y + self.vert_offset) #pylint: enable-msg=invalid-name def set_bgcolor(self, color): @@ -484,9 +495,9 @@ def set_bgcolor(self, color): :param int color: The color behind the text """ - self.write_reg(0x60, (color & 0xf800) >> 11) - self.write_reg(0x61, (color & 0x07e0) >> 5) - self.write_reg(0x62, (color & 0x001f)) + self._write_reg(0x60, (color & 0xf800) >> 11) + self._write_reg(0x61, (color & 0x07e0) >> 5) + self._write_reg(0x62, (color & 0x001f)) def set_color(self, color): """ @@ -494,9 +505,9 @@ def set_color(self, color): :param int color: The of the text or graphics """ - self.write_reg(0x63, (color & 0xf800) >> 11) - self.write_reg(0x64, (color & 0x07e0) >> 5) - self.write_reg(0x65, (color & 0x001f)) + self._write_reg(0x63, (color & 0xf800) >> 11) + self._write_reg(0x64, (color & 0x07e0) >> 5) + self._write_reg(0x65, (color & 0x001f)) #pylint: disable-msg=invalid-name def pixel(self, x, y, color): @@ -507,19 +518,18 @@ def pixel(self, x, y, color): :param int y: The Y coordinate to set the cursor :param int color: The color of the pixel """ - self.setxy(x, y) - self.write_reg(reg.MRWC, struct.pack(">H", color), True) + self.setxy(x, y + self.vert_offset) + self._write_reg(reg.MRWC, struct.pack(">H", color), True) #pylint: enable-msg=invalid-name def push_pixels(self, pixel_data): """ - Push a stream of pixel data to the screen. Additional - data can be pushed with write_data for lower overhead. + Push a stream of pixel data to the screen. :param bytearray pixel_data: Raw pixel data to push """ self._gfx_mode() - self.write_reg(reg.MRWC, pixel_data, True) + self._write_reg(reg.MRWC, pixel_data, True) #pylint: disable-msg=invalid-name,too-many-arguments def set_window(self, x, y, width, height): @@ -537,15 +547,11 @@ def set_window(self, x, y, width, height): if y + height >= self.height: height = self.height - y # X - self.write_reg(reg.HSAW0, x & 0xFF) - self.write_reg(reg.HSAW0 + 1, x >> 8) - self.write_reg(reg.HEAW0, (x + width) & 0xFF) - self.write_reg(reg.HEAW0 + 1, (x + width) >> 8) + self._write_reg16(reg.HSAW0, x) + self._write_reg16(reg.HEAW0, x + width) # Y - self.write_reg(reg.VSAW0, y & 0xFF) - self.write_reg(reg.VSAW0 + 1, y >> 8) - self.write_reg(reg.VEAW0, (y + height) & 0xFF) - self.write_reg(reg.VEAW0 + 1, (y + height) >> 8) + self._write_reg16(reg.VSAW0, y) + self._write_reg16(reg.VEAW0, y + height) #pylint: enable-msg=invalid-name,too-many-arguments class RA8875(RA8875Display): @@ -724,22 +730,18 @@ def line(self, x1, y1, x2, y2, color): self._gfx_mode() # Set Start Point - self.write_reg(0x91, x1) - self.write_reg(0x92, x1 >> 8) - self.write_reg(0x93, y1) - self.write_reg(0x94, y1 >> 8) + self._write_reg16(0x91, x1) + self._write_reg16(0x93, y1 + self.vert_offset) # Set End Point - self.write_reg(0x95, x2) - self.write_reg(0x96, x2 >> 8) - self.write_reg(0x97, y2) - self.write_reg(0x98, y2 >> 8) + self._write_reg16(0x95, x2) + self._write_reg16(0x97, y2 + self.vert_offset) self.set_color(color) # Draw it - self.write_reg(reg.DCR, 0x80) - self.wait_poll(reg.DCR, reg.DCR_LNSQTR_STATUS) + self._write_reg(reg.DCR, 0x80) + self._wait_poll(reg.DCR, reg.DCR_LNSQTR_STATUS) def round_rect(self, x, y, width, height, radius, color): """ @@ -786,105 +788,85 @@ def _circle_helper(self, x, y, radius, color, filled): self._gfx_mode() # Set X, Y, and Radius - self.write_reg(0x99, x) - self.write_reg(0x9A, x >> 8) - self.write_reg(0x9B, y) - self.write_reg(0x9C, y >> 8) - self.write_reg(0x9D, radius) + self._write_reg16(0x99, x) + self._write_reg16(0x9B, y + self.vert_offset) + self._write_reg(0x9D, radius) self.set_color(color) # Draw it - self.write_reg(reg.DCR, reg.DCR_CIRC_START | (reg.DCR_FILL if filled else reg.DCR_NOFILL)) - self.wait_poll(reg.DCR, reg.DCR_CIRC_STATUS) + self._write_reg(reg.DCR, reg.DCR_CIRC_START | (reg.DCR_FILL if filled else reg.DCR_NOFILL)) + self._wait_poll(reg.DCR, reg.DCR_CIRC_STATUS) def _rect_helper(self, x, y, width, height, color, filled): """General Rectangle Drawing Helper""" self._gfx_mode() # Set X and Y - self.write_reg(0x91, x) - self.write_reg(0x92, x >> 8) - self.write_reg(0x93, y) - self.write_reg(0x94, y >> 8) + self._write_reg16(0x91, x) + self._write_reg16(0x93, y + self.vert_offset) # Set Width and Height - self.write_reg(0x95, width) - self.write_reg(0x96, width >> 8) - self.write_reg(0x97, height) - self.write_reg(0x98, height >> 8) + self._write_reg16(0x95, width) + self._write_reg16(0x97, height + self.vert_offset) self.set_color(color) # Draw it - self.write_reg(reg.DCR, 0xB0 if filled else 0x90) - self.wait_poll(reg.DCR, reg.DCR_LNSQTR_STATUS) + self._write_reg(reg.DCR, 0xB0 if filled else 0x90) + self._wait_poll(reg.DCR, reg.DCR_LNSQTR_STATUS) def _triangle_helper(self, x1, y1, x2, y2, x3, y3, color, filled): """General Triangle Drawing Helper""" self._gfx_mode() # Set Point Coordinates - self.write_reg(0x91, x1) - self.write_reg(0x92, x1 >> 8) - self.write_reg(0x93, y1) - self.write_reg(0x94, y1 >> 8) - self.write_reg(0x95, x2) - self.write_reg(0x96, x2 >> 8) - self.write_reg(0x97, y2) - self.write_reg(0x98, y2 >> 8) - self.write_reg(0xA9, x3) - self.write_reg(0xAA, x3 >> 8) - self.write_reg(0xAB, y3) - self.write_reg(0xAC, y3 >> 8) + self._write_reg16(0x91, x1) + self._write_reg16(0x93, y1 + self.vert_offset) + self._write_reg16(0x95, x2) + self._write_reg16(0x97, y2 + self.vert_offset) + self._write_reg16(0xA9, x3) + self._write_reg16(0xAB, y3 + self.vert_offset) self.set_color(color) # Draw it - self.write_reg(reg.DCR, 0xA1 if filled else 0x81) - self.wait_poll(reg.DCR, reg.DCR_LNSQTR_STATUS) + self._write_reg(reg.DCR, 0xA1 if filled else 0x81) + self._wait_poll(reg.DCR, reg.DCR_LNSQTR_STATUS) def _curve_helper(self, x_center, y_center, h_axis, v_axis, curve_part, color, filled): """General Curve Drawing Helper""" self._gfx_mode() # Set X and Y Center - self.write_reg(0xA5, x_center) - self.write_reg(0xA6, x_center >> 8) - self.write_reg(0xA7, y_center) - self.write_reg(0xA8, y_center >> 8) + self._write_reg16(0xA5, x_center) + self._write_reg16(0xA7, y_center + self.vert_offset) # Set Long and Short Axis - self.write_reg(0xA1, h_axis) - self.write_reg(0xA2, h_axis >> 8) - self.write_reg(0xA3, v_axis) - self.write_reg(0xA4, v_axis >> 8) + self._write_reg16(0xA1, h_axis) + self._write_reg16(0xA3, v_axis) self.set_color(color) # Draw it - self.write_reg(reg.ELLIPSE, (0xD0 if filled else 0x90) | (curve_part & 0x03)) - self.wait_poll(reg.ELLIPSE, reg.ELLIPSE_STATUS) + self._write_reg(reg.ELLIPSE, (0xD0 if filled else 0x90) | (curve_part & 0x03)) + self._wait_poll(reg.ELLIPSE, reg.ELLIPSE_STATUS) def _ellipse_helper(self, x_center, y_center, h_axis, v_axis, color, filled): """General Ellipse Drawing Helper""" self._gfx_mode() # Set X and Y Center - self.write_reg(0xA5, x_center) - self.write_reg(0xA6, x_center >> 8) - self.write_reg(0xA7, y_center) - self.write_reg(0xA8, y_center >> 8) + self._write_reg16(0xA5, x_center) + self._write_reg16(0xA7, y_center + self.vert_offset) # Set Long and Short Axis - self.write_reg(0xA1, h_axis) - self.write_reg(0xA2, h_axis >> 8) - self.write_reg(0xA3, v_axis) - self.write_reg(0xA4, v_axis >> 8) + self._write_reg16(0xA1, h_axis) + self._write_reg16(0xA3, v_axis) self.set_color(color) # Draw it - self.write_reg(reg.ELLIPSE, 0xC0 if filled else 0x80) - self.wait_poll(reg.ELLIPSE, reg.ELLIPSE_STATUS) + self._write_reg(reg.ELLIPSE, 0xC0 if filled else 0x80) + self._wait_poll(reg.ELLIPSE, reg.ELLIPSE_STATUS) #pylint: enable-msg=invalid-name,too-many-arguments diff --git a/adafruit_ra8875/registers.py b/adafruit_ra8875/registers.py index 6a7699a..3756f8a 100755 --- a/adafruit_ra8875/registers.py +++ b/adafruit_ra8875/registers.py @@ -45,18 +45,10 @@ GPIOX = 0xC7 PLLC1 = 0x88 -PLLC1_PLLDIV2 = 0x80 PLLC1_PLLDIV1 = 0x00 PLLC2 = 0x89 -PLLC2_DIV1 = 0x00 -PLLC2_DIV2 = 0x01 PLLC2_DIV4 = 0x02 -PLLC2_DIV8 = 0x03 -PLLC2_DIV16 = 0x04 -PLLC2_DIV32 = 0x05 -PLLC2_DIV64 = 0x06 -PLLC2_DIV128 = 0x07 SYSR = 0x10 SYSR_8BPP = 0x00 @@ -85,11 +77,8 @@ HPWR_HIGH = 0x80 VDHR0 = 0x19 -VDHR1 = 0x1A VNDR0 = 0x1B -VNDR1 = 0x1C VSTR0 = 0x1D -VSTR1 = 0x1E VPWR = 0x1F VPWR_LOW = 0x00 VPWR_HIGH = 0x80 @@ -98,14 +87,10 @@ FNCR1 = 0x22 HSAW0 = 0x30 -HSAW1 = 0x31 VSAW0 = 0x32 -VSAW1 = 0x33 HEAW0 = 0x34 -HEAW1 = 0x35 VEAW0 = 0x36 -VEAW1 = 0x37 MCLR = 0x8E MCLR_START = 0x80 @@ -135,9 +120,7 @@ MWCR0_TXTMODE = 0x80 CURH0 = 0x46 -CURH1 = 0x47 CURV0 = 0x48 -CURV1 = 0x49 P1CR = 0x8A P1CR_ENABLE = 0x80 @@ -154,56 +137,22 @@ P2CR_PWMOUT = 0x00 P2DCR = 0x8D -PWM_CLK_DIV1 = 0x00 -PWM_CLK_DIV2 = 0x01 -PWM_CLK_DIV4 = 0x02 -PWM_CLK_DIV8 = 0x03 -PWM_CLK_DIV16 = 0x04 -PWM_CLK_DIV32 = 0x05 -PWM_CLK_DIV64 = 0x06 -PWM_CLK_DIV128 = 0x07 -PWM_CLK_DIV256 = 0x08 -PWM_CLK_DIV512 = 0x09 PWM_CLK_DIV1024 = 0x0A -PWM_CLK_DIV2048 = 0x0B -PWM_CLK_DIV4096 = 0x0C -PWM_CLK_DIV8192 = 0x0D -PWM_CLK_DIV16384 = 0x0E -PWM_CLK_DIV32768 = 0x0F TPCR0 = 0x70 TPCR0_ENABLE = 0x80 TPCR0_DISABLE = 0x00 -TPCR0_WAIT_512CLK = 0x00 -TPCR0_WAIT_1024CLK = 0x10 -TPCR0_WAIT_2048CLK = 0x20 TPCR0_WAIT_4096CLK = 0x30 -TPCR0_WAIT_8192CLK = 0x40 -TPCR0_WAIT_16384CLK = 0x50 -TPCR0_WAIT_32768CLK = 0x60 -TPCR0_WAIT_65536CLK = 0x70 TPCR0_WAKEENABLE = 0x08 TPCR0_WAKEDISABLE = 0x00 -TPCR0_ADCCLK_DIV1 = 0x00 -TPCR0_ADCCLK_DIV2 = 0x01 TPCR0_ADCCLK_DIV4 = 0x02 -TPCR0_ADCCLK_DIV8 = 0x03 TPCR0_ADCCLK_DIV16 = 0x04 -TPCR0_ADCCLK_DIV32 = 0x05 -TPCR0_ADCCLK_DIV64 = 0x06 -TPCR0_ADCCLK_DIV128 = 0x07 TPCR1 = 0x71 TPCR1_AUTO = 0x00 TPCR1_MANUAL = 0x40 -TPCR1_VREFINT = 0x00 -TPCR1_VREFEXT = 0x20 TPCR1_DEBOUNCE = 0x04 TPCR1_NODEBOUNCE = 0x00 -TPCR1_IDLE = 0x00 -TPCR1_WAIT = 0x01 -TPCR1_LATCHX = 0x02 -TPCR1_LATCHY = 0x03 TPXH = 0x72 TPYH = 0x73 diff --git a/examples/ra8875_bmptest.py b/examples/ra8875_bmptest.py index 6de9eb1..0ad1118 100755 --- a/examples/ra8875_bmptest.py +++ b/examples/ra8875_bmptest.py @@ -17,7 +17,7 @@ rst_pin = digitalio.DigitalInOut(board.D10) # Config for display baudrate (default max is 6mhz): -BAUDRATE = 6000000 +BAUDRATE = 8000000 # Setup SPI bus using hardware SPI: spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)