-
Notifications
You must be signed in to change notification settings - Fork 231
si5351: complete refactor for more complete interface #832
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
Conversation
b03dbff to
fc08c37
Compare
fc08c37 to
b5d4cf2
Compare
soypat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple things I noticed to improve API
si5351/si5351.go
Outdated
| d.rw.Write8(CRYSTAL_INTERNAL_LOAD_CAPACITANCE, d.crystalLoad) | ||
| // Configure initializes the SI5351 with the specified crystal load capacitance, | ||
| // reference oscillator frequency, and frequency correction. | ||
| func (d *Device) Configure(xtalLoadC uint8, xoFreq uint32, correction int32) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you captured all configuration options here- or should we have a Config struct for future additions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Config type for consistency. Not sure if needed for expansion, but we're prepared just in case.
| // reference oscillator frequency, and frequency correction. | ||
| func (d *Device) Configure(xtalLoadC uint8, xoFreq uint32, correction int32) error { | ||
| // Check for device on bus | ||
| if err := d.bus.Tx(uint16(d.Address), []byte{}, []byte{0}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use d.rw instead to ensure no allocation here, or even add a IsConnected method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think it allocates here.
si5351/si5351.go
Outdated
| } | ||
|
|
||
| // SetMultisynthSource sets the PLL source for a multisynth. | ||
| func (d *Device) SetMultisynthSource(clk uint8, pll uint8) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pll is a an enum- maybe define enums for all these types to make API usage simpler ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a number of types for clarify and safety. Good call!
si5351/si5351.go
Outdated
| } | ||
|
|
||
| // EnableOutput enables or disables a clock output. | ||
| func (d *Device) EnableOutput(clk uint8, enable bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clk seems to also be an enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
si5351/si5351.go
Outdated
| case pll == PLL_B && !d.pllbConfigured: | ||
| // Clock source options | ||
| const ( | ||
| ClockSourceXTAL = iota |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a ClockSource type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
si5351/si5351.go
Outdated
|
|
||
| // Clock output identifiers | ||
| const ( | ||
| Clock0 uint8 = iota |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clock type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
si5351/si5351.go
Outdated
|
|
||
| // Reference oscillator identifiers | ||
| const ( | ||
| PLLInputXO = iota |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PLL type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
db6fe38 to
d2eb60c
Compare
This completely refactors the interface and implementation for the si5351 clock generator. The interface based on the Arduino implementation was both somewhat hard to work with and also missing a number of important features that are needed to use this chip for RF communication. Instead this new implementation draws inspiration from the efforts of the Traquino community mostly using the rp2040 processor. The TinyGo implementation is based on the patterns and code in the drivers repo for other i2c devices. It also includes some basic unit tests which are not comprehensive but at least provide some coverage. Signed-off-by: deadprogram <ron@hybridgroup.com>
soypat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff! thanks for the contribution ron1
d2eb60c to
c3a56b7
Compare
|
Made one last change to the naming on the config fields for clarity. |
|
Thanks for all the review/feedback @soypat now merging. |

This PR completely refactors the interface and implementation for the
si5351clock generator. The interface based on the Arduino implementation was both somewhat hard to work with and also missing a number of important features that are needed to use this chip for RF communication.Instead this new implementation draws inspiration from the efforts of the Traquito community. They work entirely with the rp2040 processor.
However, the actual implementation in this PR is based on the patterns and code in the TinyGo drivers repo for other i2c devices. It also includes some basic unit tests which are not comprehensive but at least provide some coverage. Of course this implementation is not tied to any particular target platform.