Added RTC for all Inkplates

master
Robert Sorić 2024-02-19 15:17:21 +01:00
parent 5477f30992
commit 68850e9d2b
15 changed files with 807 additions and 2 deletions

View File

@ -0,0 +1,38 @@
# This example will show you how to use the onboard RTC to preserve time across reboots
# Include all the required libraries
from inkplate10 import Inkplate
import time
# Create Inkplate object in 1-bit mode, black and white colors only
# For 2-bit grayscale, see basicGrayscale.py
display = Inkplate(Inkplate.INKPLATE_1BIT)
# Main function
if __name__ == "__main__":
# Initialize the display, needs to be called only once
display.begin()
# Clear the frame buffer
display.clearDisplay()
# This has to be called every time you want to update the screen
# Drawing or printing text will have no effect on the display itself before you call this function
display.display()
# This is how to set the RTC's time
# Arguments are hour, minute, seconds
display.rtcSetTime(9,39,10)
# And this is the date
# Arguments are weekday, day in month, month and year
display.rtcSetDate(5,9,2,2024)
# Show the set time
print(display.rtcGetData())
# Let's wait 10 seconds
time.sleep(10)
# Let's see if the time has updated
print(display.rtcGetData())

View File

@ -2,7 +2,6 @@
# Include all the required libraries
from inkplate5 import Inkplate
from soldered_logo import *
import time
# Create Inkplate object in 1-bit mode, black and white colors only

38
Examples/Inkplate6/RTC.py Normal file
View File

@ -0,0 +1,38 @@
# This example will show you how to use the onboard RTC to preserve time across reboots
# Include all the required libraries
from inkplate6 import Inkplate
import time
# Create Inkplate object in 1-bit mode, black and white colors only
# For 2-bit grayscale, see basicGrayscale.py
display = Inkplate(Inkplate.INKPLATE_1BIT)
# Main function
if __name__ == "__main__":
# Initialize the display, needs to be called only once
display.begin()
# Clear the frame buffer
display.clearDisplay()
# This has to be called every time you want to update the screen
# Drawing or printing text will have no effect on the display itself before you call this function
display.display()
# This is how to set the RTC's time
# Arguments are hour, minute, seconds
display.rtcSetTime(9,39,10)
# And this is the date
# Arguments are weekday, day in month, month and year
display.rtcSetDate(5,9,2,2024)
# Show the set time
print(display.rtcGetData())
# Let's wait 10 seconds
time.sleep(10)
# Let's see if the time has updated
print(display.rtcGetData())

View File

@ -0,0 +1,38 @@
# This example will show you how to use the onboard RTC to preserve time across reboots
# Include all the required libraries
from inkplate6COLOR import Inkplate
import time
# Create Inkplate object in 1-bit mode, black and white colors only
# For 2-bit grayscale, see basicGrayscale.py
display = Inkplate(Inkplate.INKPLATE_1BIT)
# Main function
if __name__ == "__main__":
# Initialize the display, needs to be called only once
display.begin()
# Clear the frame buffer
display.clearDisplay()
# This has to be called every time you want to update the screen
# Drawing or printing text will have no effect on the display itself before you call this function
display.display()
# This is how to set the RTC's time
# Arguments are hour, minute, seconds
display.rtcSetTime(9,39,10)
# And this is the date
# Arguments are weekday, day in month, month and year
display.rtcSetDate(5,9,2,2024)
# Show the set time
print(display.rtcGetData())
# Let's wait 10 seconds
time.sleep(10)
# Let's see if the time has updated
print(display.rtcGetData())

View File

@ -0,0 +1,38 @@
# This example will show you how to use the onboard RTC to preserve time across reboots
# Include all the required libraries
from inkplate6PLUS import Inkplate
import time
# Create Inkplate object in 1-bit mode, black and white colors only
# For 2-bit grayscale, see basicGrayscale.py
display = Inkplate(Inkplate.INKPLATE_1BIT)
# Main function
if __name__ == "__main__":
# Initialize the display, needs to be called only once
display.begin()
# Clear the frame buffer
display.clearDisplay()
# This has to be called every time you want to update the screen
# Drawing or printing text will have no effect on the display itself before you call this function
display.display()
# This is how to set the RTC's time
# Arguments are hour, minute, seconds
display.rtcSetTime(9,39,10)
# And this is the date
# Arguments are weekday, day in month, month and year
display.rtcSetDate(5,9,2,2024)
# Show the set time
print(display.rtcGetData())
# Let's wait 10 seconds
time.sleep(10)
# Let's see if the time has updated
print(display.rtcGetData())

View File

@ -0,0 +1,38 @@
# This example will show you how to use the onboard RTC to preserve time across reboots
# Include all the required libraries
from soldered_inkplate10 import Inkplate
import time
# Create Inkplate object in 1-bit mode, black and white colors only
# For 2-bit grayscale, see basicGrayscale.py
display = Inkplate(Inkplate.INKPLATE_1BIT)
# Main function
if __name__ == "__main__":
# Initialize the display, needs to be called only once
display.begin()
# Clear the frame buffer
display.clearDisplay()
# This has to be called every time you want to update the screen
# Drawing or printing text will have no effect on the display itself before you call this function
display.display()
# This is how to set the RTC's time
# Arguments are hour, minute, seconds
display.rtcSetTime(9,39,10)
# And this is the date
# Arguments are weekday, day in month, month and year
display.rtcSetDate(5,9,2,2024)
# Show the set time
print(display.rtcGetData())
# Let's wait 10 seconds
time.sleep(10)
# Let's see if the time has updated
print(display.rtcGetData())

View File

@ -0,0 +1,38 @@
# This example will show you how to use the onboard RTC to preserve time across reboots
# Include all the required libraries
from soldered_inkplate6 import Inkplate
import time
# Create Inkplate object in 1-bit mode, black and white colors only
# For 2-bit grayscale, see basicGrayscale.py
display = Inkplate(Inkplate.INKPLATE_1BIT)
# Main function
if __name__ == "__main__":
# Initialize the display, needs to be called only once
display.begin()
# Clear the frame buffer
display.clearDisplay()
# This has to be called every time you want to update the screen
# Drawing or printing text will have no effect on the display itself before you call this function
display.display()
# This is how to set the RTC's time
# Arguments are hour, minute, seconds
display.rtcSetTime(9,39,10)
# And this is the date
# Arguments are weekday, day in month, month and year
display.rtcSetDate(5,9,2,2024)
# Show the set time
print(display.rtcGetData())
# Let's wait 10 seconds
time.sleep(10)
# Let's see if the time has updated
print(display.rtcGetData())

View File

@ -0,0 +1,38 @@
# This example will show you how to use the onboard RTC to preserve time across reboots
# Include all the required libraries
from soldered_inkplate6PLUS import Inkplate
import time
# Create Inkplate object in 1-bit mode, black and white colors only
# For 2-bit grayscale, see basicGrayscale.py
display = Inkplate(Inkplate.INKPLATE_1BIT)
# Main function
if __name__ == "__main__":
# Initialize the display, needs to be called only once
display.begin()
# Clear the frame buffer
display.clearDisplay()
# This has to be called every time you want to update the screen
# Drawing or printing text will have no effect on the display itself before you call this function
display.display()
# This is how to set the RTC's time
# Arguments are hour, minute, seconds
display.rtcSetTime(9,39,10)
# And this is the date
# Arguments are weekday, day in month, month and year
display.rtcSetDate(5,9,2,2024)
# Show the set time
print(display.rtcGetData())
# Let's wait 10 seconds
time.sleep(10)
# Let's see if the time has updated
print(display.rtcGetData())

View File

@ -58,6 +58,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
# Inkplate provides access to the pins of the Inkplate 6 as well as to low-level display
# functions.
RTC_I2C_ADDR = 0x51
RTC_RAM_by = 0x03
RTC_DAY_ADDR = 0x07
RTC_SECOND_ADDR = 0x04
class _Inkplate:
@classmethod
@ -176,6 +180,70 @@ class _Inkplate:
def _tps65186_read(cls, reg):
cls._i2c.readfrom_mem(TPS65186_addr, reg, 1)[0]
@classmethod
def rtc_dec_to_bcd(cls, val):
return (val // 10 * 16) + (val % 10)
@classmethod
def rtc_bcd_to_dec(cls, val):
return (val // 16 * 10) + (val % 16)
@classmethod
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
cls.rtc_dec_to_bcd(rtc_second),
cls.rtc_dec_to_bcd(rtc_minute),
cls.rtc_dec_to_bcd(rtc_hour)
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
rtcYear = rtc_yr - 2000
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
data = bytearray([
RTC_DAY_ADDR,
cls.rtc_dec_to_bcd(rtc_day),
cls.rtc_dec_to_bcd(rtc_weekday),
cls.rtc_dec_to_bcd(rtc_month),
cls.rtc_dec_to_bcd(rtcYear),
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_get_rtc_data(cls):
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
return {
'second': rtc_second,
'minute': rtc_minute,
'hour': rtc_hour,
'day': rtc_day,
'weekday': rtc_weekday,
'month': rtc_month,
'year': rtc_year
}
# power_on turns the voltage regulator on and wakes up the display (GMODE and OE)
@classmethod
def power_on(cls):
@ -1084,3 +1152,12 @@ class Inkplate:
val >>= 1
self.drawPixel(x + i, y + h - j, val)
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
def rtcGetData(self):
return _Inkplate.rtc_get_rtc_data()

View File

@ -61,6 +61,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
# Inkplate provides access to the pins of the Inkplate 6 as well as to low-level display
# functions.
RTC_I2C_ADDR = 0x51
RTC_RAM_by = 0x03
RTC_DAY_ADDR = 0x07
RTC_SECOND_ADDR = 0x04
class _Inkplate:
@classmethod
@ -179,6 +183,70 @@ class _Inkplate:
def _tps65186_read(cls, reg):
cls._i2c.readfrom_mem(TPS65186_addr, reg, 1)[0]
@classmethod
def rtc_dec_to_bcd(cls, val):
return (val // 10 * 16) + (val % 10)
@classmethod
def rtc_bcd_to_dec(cls, val):
return (val // 16 * 10) + (val % 16)
@classmethod
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
cls.rtc_dec_to_bcd(rtc_second),
cls.rtc_dec_to_bcd(rtc_minute),
cls.rtc_dec_to_bcd(rtc_hour)
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
rtcYear = rtc_yr - 2000
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
data = bytearray([
RTC_DAY_ADDR,
cls.rtc_dec_to_bcd(rtc_day),
cls.rtc_dec_to_bcd(rtc_weekday),
cls.rtc_dec_to_bcd(rtc_month),
cls.rtc_dec_to_bcd(rtcYear),
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_get_rtc_data(cls):
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
return {
'second': rtc_second,
'minute': rtc_minute,
'hour': rtc_hour,
'day': rtc_day,
'weekday': rtc_weekday,
'month': rtc_month,
'year': rtc_year
}
# power_on turns the voltage regulator on and wakes up the display (GMODE and OE)
@classmethod
def power_on(cls):
@ -1048,3 +1116,12 @@ class Inkplate:
val >>= 1
self.drawPixel(x + i, y + h - j, val)
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
def rtcGetData(self):
return _Inkplate.rtc_get_rtc_data()

View File

@ -72,6 +72,10 @@ IO_PIN_B5 = const(13)
IO_PIN_B6 = const(14)
IO_PIN_B7 = const(15)
RTC_I2C_ADDR = 0x51
RTC_RAM_by = 0x03
RTC_DAY_ADDR = 0x07
RTC_SECOND_ADDR = 0x04
class Inkplate:
BLACK = const(0b00000000) # 0
@ -275,6 +279,70 @@ class Inkplate:
def gpioExpanderPin(self, pin, mode):
return gpioPin(self._PCAL6416A, pin, mode)
@classmethod
def rtc_dec_to_bcd(cls, val):
return (val // 10 * 16) + (val % 10)
@classmethod
def rtc_bcd_to_dec(cls, val):
return (val // 16 * 10) + (val % 16)
@classmethod
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
cls.rtc_dec_to_bcd(rtc_second),
cls.rtc_dec_to_bcd(rtc_minute),
cls.rtc_dec_to_bcd(rtc_hour)
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
rtcYear = rtc_yr - 2000
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
data = bytearray([
RTC_DAY_ADDR,
cls.rtc_dec_to_bcd(rtc_day),
cls.rtc_dec_to_bcd(rtc_weekday),
cls.rtc_dec_to_bcd(rtc_month),
cls.rtc_dec_to_bcd(rtcYear),
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_get_rtc_data(cls):
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
return {
'second': rtc_second,
'minute': rtc_minute,
'hour': rtc_hour,
'day': rtc_day,
'weekday': rtc_weekday,
'month': rtc_month,
'year': rtc_year
}
@classmethod
def clean(self):
if not self._panelState:
@ -510,3 +578,12 @@ class Inkplate:
self.writePixel(x1 + x, y1 + y, pixel_value1)
if x2 < width and y2 < height:
self.writePixel(x2 + x, y2 + y, pixel_value2)
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
def rtcGetData(self):
return _Inkplate.rtc_get_rtc_data()

View File

@ -67,6 +67,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
# Inkplate provides access to the pins of the Inkplate 6 PLUS as well as to low-level display
# functions.
RTC_I2C_ADDR = 0x51
RTC_RAM_by = 0x03
RTC_DAY_ADDR = 0x07
RTC_SECOND_ADDR = 0x04
class _Inkplate:
@classmethod
@ -180,6 +184,71 @@ class _Inkplate:
cls._i2c.writeto(FRONTLIGHT_ADDRESS, bytes((0,)))
cls._i2c.writeto(FRONTLIGHT_ADDRESS, bytes((value,)))
# RTC
@classmethod
def rtc_dec_to_bcd(cls, val):
return (val // 10 * 16) + (val % 10)
@classmethod
def rtc_bcd_to_dec(cls, val):
return (val // 16 * 10) + (val % 16)
@classmethod
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
cls.rtc_dec_to_bcd(rtc_second),
cls.rtc_dec_to_bcd(rtc_minute),
cls.rtc_dec_to_bcd(rtc_hour)
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
rtcYear = rtc_yr - 2000
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
data = bytearray([
RTC_DAY_ADDR,
cls.rtc_dec_to_bcd(rtc_day),
cls.rtc_dec_to_bcd(rtc_weekday),
cls.rtc_dec_to_bcd(rtc_month),
cls.rtc_dec_to_bcd(rtcYear),
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_get_rtc_data(cls):
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
return {
'second': rtc_second,
'minute': rtc_minute,
'hour': rtc_hour,
'day': rtc_day,
'weekday': rtc_weekday,
'month': rtc_month,
'year': rtc_year
}
# Touchscreen
@classmethod
@ -1273,3 +1342,12 @@ class Inkplate:
def tsShutdown(self):
_Inkplate.tsShutdown()
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
def rtcGetData(self):
return _Inkplate.rtc_get_rtc_data()

View File

@ -56,6 +56,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
# Inkplate provides access to the pins of the Inkplate 10 as well as to low-level display
# functions.
RTC_I2C_ADDR = 0x51
RTC_RAM_by = 0x03
RTC_DAY_ADDR = 0x07
RTC_SECOND_ADDR = 0x04
class _Inkplate:
@classmethod
@ -324,6 +328,70 @@ class _Inkplate:
cls.vscan_start()
cls.fill_screen(data)
@classmethod
def rtc_dec_to_bcd(cls, val):
return (val // 10 * 16) + (val % 10)
@classmethod
def rtc_bcd_to_dec(cls, val):
return (val // 16 * 10) + (val % 16)
@classmethod
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
cls.rtc_dec_to_bcd(rtc_second),
cls.rtc_dec_to_bcd(rtc_minute),
cls.rtc_dec_to_bcd(rtc_hour)
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
rtcYear = rtc_yr - 2000
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
data = bytearray([
RTC_DAY_ADDR,
cls.rtc_dec_to_bcd(rtc_day),
cls.rtc_dec_to_bcd(rtc_weekday),
cls.rtc_dec_to_bcd(rtc_month),
cls.rtc_dec_to_bcd(rtcYear),
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_get_rtc_data(cls):
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
return {
'second': rtc_second,
'minute': rtc_minute,
'hour': rtc_hour,
'day': rtc_day,
'weekday': rtc_weekday,
'month': rtc_month,
'year': rtc_year
}
class InkplateMono(framebuf.FrameBuffer):
def __init__(self):
@ -1112,3 +1180,12 @@ class Inkplate:
val >>= 1
self.drawPixel(x + i, y + h - j, val)
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
def rtcGetData(self):
return _Inkplate.rtc_get_rtc_data()

View File

@ -61,6 +61,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
# Inkplate provides access to the pins of the Inkplate 6 as well as to low-level display
# functions.
RTC_I2C_ADDR = 0x51
RTC_RAM_by = 0x03
RTC_DAY_ADDR = 0x07
RTC_SECOND_ADDR = 0x04
class _Inkplate:
@classmethod
@ -325,6 +329,70 @@ class _Inkplate:
cls.vscan_start()
cls.fill_screen(data)
@classmethod
def rtc_dec_to_bcd(cls, val):
return (val // 10 * 16) + (val % 10)
@classmethod
def rtc_bcd_to_dec(cls, val):
return (val // 16 * 10) + (val % 16)
@classmethod
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
cls.rtc_dec_to_bcd(rtc_second),
cls.rtc_dec_to_bcd(rtc_minute),
cls.rtc_dec_to_bcd(rtc_hour)
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
rtcYear = rtc_yr - 2000
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
data = bytearray([
RTC_DAY_ADDR,
cls.rtc_dec_to_bcd(rtc_day),
cls.rtc_dec_to_bcd(rtc_weekday),
cls.rtc_dec_to_bcd(rtc_month),
cls.rtc_dec_to_bcd(rtcYear),
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_get_rtc_data(cls):
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
return {
'second': rtc_second,
'minute': rtc_minute,
'hour': rtc_hour,
'day': rtc_day,
'weekday': rtc_weekday,
'month': rtc_month,
'year': rtc_year
}
class InkplateMono(framebuf.FrameBuffer):
def __init__(self):
@ -1074,3 +1142,12 @@ class Inkplate:
val >>= 1
self.drawPixel(x + i, y + h - j, val)
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
def rtcGetData(self):
return _Inkplate.rtc_get_rtc_data()

View File

@ -67,6 +67,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
# Inkplate provides access to the pins of the Inkplate 6 PLUS as well as to low-level display
# functions.
RTC_I2C_ADDR = 0x51
RTC_RAM_by = 0x03
RTC_DAY_ADDR = 0x07
RTC_SECOND_ADDR = 0x04
class _Inkplate:
@classmethod
@ -197,6 +201,70 @@ class _Inkplate:
data_to_send = bytearray([0, value])
cls._i2c.writeto(FRONTLIGHT_ADDRESS, data_to_send)
@classmethod
def rtc_dec_to_bcd(cls, val):
return (val // 10 * 16) + (val % 10)
@classmethod
def rtc_bcd_to_dec(cls, val):
return (val // 16 * 10) + (val % 16)
@classmethod
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
cls.rtc_dec_to_bcd(rtc_second),
cls.rtc_dec_to_bcd(rtc_minute),
cls.rtc_dec_to_bcd(rtc_hour)
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
rtcYear = rtc_yr - 2000
data = bytearray([
RTC_RAM_by,
170, # Write in RAM 170 to know that RTC is set
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
data = bytearray([
RTC_DAY_ADDR,
cls.rtc_dec_to_bcd(rtc_day),
cls.rtc_dec_to_bcd(rtc_weekday),
cls.rtc_dec_to_bcd(rtc_month),
cls.rtc_dec_to_bcd(rtcYear),
])
cls._i2c.writeto(RTC_I2C_ADDR, data)
@classmethod
def rtc_get_rtc_data(cls):
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
return {
'second': rtc_second,
'minute': rtc_minute,
'hour': rtc_hour,
'day': rtc_day,
'weekday': rtc_weekday,
'month': rtc_month,
'year': rtc_year
}
# Touchscreen
@classmethod
def touchInArea(cls, x, y, width, height):
@ -1325,4 +1393,13 @@ class Inkplate:
_Inkplate.frontlight(value)
def setFrontlight(self, value):
_Inkplate.setFrontlight(value)
_Inkplate.setFrontlight(value)
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
def rtcGetData(self):
return _Inkplate.rtc_get_rtc_data()