Skip to content

Circuitpython port #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 5, 2019
Merged

Circuitpython port #26

merged 10 commits into from
Sep 5, 2019

Conversation

TarjanPeter
Copy link
Contributor

Some minor changes were needed to make it work on Circuitpython (I tested on an Adafruit Trinket M0). Mostly it was about replacing time.sleep_ms and time.sleep_us with time.sleep plus a few more odds and ends.

lcd/lcd_api.py Outdated
time.sleep(0.00004)
for i in range(8):
self.hal_write_data(charmap[i])
time.sleep(0.00004)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So lcd_api.py is a common file, so you'll need to factor the sleeping into the hal layer.

Also, the original files all have linux line endings. Please convert before committing, otherwise you wind up changing every line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the EOLs (I think). I don't understand what you mean by factoring the sleeping into the hal layer.
Sorry for the bumbling, I'm new to this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll notice that inside lcd_api.py it has lots of calls to self.hal_xxx (self.hal_write_command for example).

hal_write_command is implemented in the the file that's platform specific (in your case circuitpython_i2c_lcd.py).

In order to maintain backwards compatibility, we'd probably need to provide a default function which calls time.sleep_us that the hal layer can override.

So have LcdApi implement a hal_sleep_us function which calls sleep_us (so we don't break existing code) and then provide a hal_sleep_us function in the circuitpython code which calls time.sleep

The call to sleep_us managed to sneak by me and crept in when custom_char support was added. If I had noticed it, I would have had the original author change it then.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be good to squash the commits together. In this case it will make viewing the differences easier.

@TarjanPeter
Copy link
Contributor Author

Thanks for the clarification. Squashed and implemented.

@@ -80,3 +80,8 @@ def hal_write_data(self, data):
byte = (MASK_RS | (self.backlight << SHIFT_BACKLIGHT) | ((data & 0x0f) << SHIFT_DATA))
self.i2c.writeto(self.i2c_addr, bytearray([byte | MASK_E]))
self.i2c.writeto(self.i2c_addr, bytearray([byte]))

def hal_sleep_us(self, data):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename data to be usecs. Otherwise this looks great.

lcd/lcd_api.py Outdated
@@ -193,3 +193,7 @@ def hal_write_data(self, data):
function.
"""
raise NotImplementedError

def hal_sleep_us(self, data):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here. Rename data to be usecs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and done.

def test_main():
"""Test function for verifying basic functionality."""
print("Running test_main")
i2c = busio.I2C(board.SCL, board.SDA)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should use spaces rather than tabs for indentation (4 spaces is consistent with the remaining files)

@dhylands dhylands merged commit 87ca81a into dhylands:master Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants