-
Notifications
You must be signed in to change notification settings - Fork 2
feat(mcal): implement SpiMaster peripheral for stm32f, lnx, and cli #539
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
base: main
Are you sure you want to change the base?
Conversation
Add SpiMaster implementations across all three platforms: - stm32f: HAL-based implementation with GPIO chip select control - lnx: spidev interface with configurable mode and speed - cli: interactive hex I/O for testing and simulation Includes Init()/Setup() functions for future bindings integration.
77ec816 to
610a802
Compare
| } | ||
|
|
||
| // initialize chip select pin as output, set high (inactive) | ||
| GPIO_InitTypeDef GPIO_InitStruct = {0}; |
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.
glad you learned stm HAL pin initialization, but you don't need to configure the chip select pin manually. we will configure in in CubeMX so you can assume the Port/Pin is is initialized already
| /// initialize the SPI peripheral | ||
| /// must be called before using any transmission methods | ||
| /// typically called from bindings::Initialize() | ||
| void Init() { |
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 like the Init() function! it's a good idea since we want to guarantee that the CS pin is high on startup
I've seen the if(initialized_) and if(!initialized_) pattern used before, but I find it usually only clutters the code and doesn't provide any value. In Init() there is no harm in initializing twice (the outcome is the same), and in Transmit() / Receive() / TransmitReceive(), the transmission won't happen until you separately edit the code to call Init()
We don't need to protect the developer from forgetting to call Init(), so can you remove the initialized_ field and if(initialized_ checks? Similarly, we don't need to check that hspi != null
| } | ||
|
|
||
| /// check if the spi peripheral has been initialized | ||
| bool IsInitialized() const { |
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.
don't need this, see comment above
| } | ||
|
|
||
| /// get the underlying hal spi handle | ||
| SPI_HandleTypeDef* GetHandle() const { |
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 don't think we need this. When would it be called?
| /// initialize the spi device | ||
| /// opens the device file and configures spi parameters | ||
| void Setup() { | ||
| if (initialized_) { |
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.
see this comment https://github.com/macformula/racecar/pull/539/files#r2528588442, don't need the initialized field & checks
Add SpiMaster implementations across all three platforms:
Includes Init()/Setup() functions for future bindings integration.