-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add SPI Mode Enum to LinuxSpiDriver #2097
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
Changes from all commits
c44dba2
01e1e6d
a019f4d
96c0c8f
5be4a9f
2153724
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,8 @@ namespace Drv { | |
|
|
||
| bool LinuxSpiDriverComponentImpl::open(NATIVE_INT_TYPE device, | ||
| NATIVE_INT_TYPE select, | ||
| SpiFrequency clock) { | ||
| SpiFrequency clock, | ||
| SpiMode spiMode) { | ||
|
|
||
| this->m_device = device; | ||
| this->m_select = select; | ||
|
|
@@ -97,9 +98,29 @@ namespace Drv { | |
|
|
||
| // Configure: | ||
| /* | ||
| * SPI Mode 0 | ||
| * SPI Mode 0, 1, 2, 3 | ||
| */ | ||
| U8 mode = SPI_MODE_0; // Mode 0 (CPOL = 0, CPHA = 0) | ||
|
|
||
| U8 mode; // Mode Select (CPOL = 0/1, CPHA = 0/1) | ||
| switch(spiMode) { | ||
Check warningCode scanning / CodeQL Unchecked function argument
This use of parameter spiMode has not been checked.
|
||
| case SpiMode::SPI_MODE_CPOL_LOW_CPHA_LOW: | ||
| mode = SPI_MODE_0; | ||
| break; | ||
| case SpiMode::SPI_MODE_CPOL_LOW_CPHA_HIGH: | ||
| mode = SPI_MODE_1; | ||
| break; | ||
| case SpiMode::SPI_MODE_CPOL_HIGH_CPHA_LOW: | ||
| mode = SPI_MODE_2; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed! Missing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Just added the missing statements |
||
| break; | ||
| case SpiMode::SPI_MODE_CPOL_HIGH_CPHA_HIGH: | ||
| mode = SPI_MODE_3; | ||
| break; | ||
| default: | ||
| //Assert if the device SPI Mode is not in the correct range | ||
| FW_ASSERT(0, spiMode); | ||
| break; | ||
| } | ||
|
|
||
| ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); | ||
| if (ret == -1) { | ||
| DEBUG_PRINT("ioctl SPI_IOC_WR_MODE fd %d failed. %d\n",fd,errno); | ||
|
|
||
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.
We should assert that spiMode is in the correct range: