-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
604c5d4
commit 1abcdf5
Showing
6 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Checks: > | ||
-*, | ||
bugprone-*, | ||
performance-*, | ||
portability-*, | ||
readability-*, | ||
modernize-*, | ||
cppcoreguidelines-*, | ||
clang-analyzer-*, | ||
cert-* | ||
WarningsAsErrors: '*' | ||
HeaderFilterRegex: '.*' | ||
FormatStyle: 'file' | ||
|
||
CheckOptions: | ||
- key: modernize-use-auto | ||
value: '0' | ||
- key: modernize-use-using | ||
value: '0' | ||
- key: modernize-avoid-bind | ||
value: '0' | ||
- key: modernize-use-nullptr | ||
value: '0' | ||
- key: modernize-use-override | ||
value: '0' | ||
- key: cppcoreguidelines-avoid-magic-numbers | ||
value: '0' | ||
- key: cppcoreguidelines-pro-bounds-array-to-pointer-decay | ||
value: '0' | ||
- key: cppcoreguidelines-pro-type-vararg | ||
value: '0' | ||
- key: readability-magic-numbers | ||
value: '1' | ||
- key: bugprone-exception-escape | ||
value: '0' | ||
- key: cert-msc30-c | ||
value: '0' | ||
- key: cert-msc50-cpp | ||
value: '0' | ||
- key: readability-function-cognitive-complexity-threshold | ||
value: '15' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//! SPI object | ||
|
||
const c = @cImport({ | ||
@cInclude("board.h"); | ||
@cInclude("miso.h"); | ||
@cInclude("miso_config.h"); | ||
}); | ||
|
||
const freertos = @import("freertos.zig"); | ||
|
||
const ecode = c.Ecode_t; | ||
//const spiDrvHandle | ||
const txferElement = struct { | ||
status: ecode, // status | ||
items: isize, // number of items transfered | ||
}; | ||
|
||
pub fn Spi() type { | ||
return struct { | ||
spidrvHandle: c.SPIDRV_HandleData_t, | ||
|
||
txQueue: freertos.StaticQueue(txferElement, 1), | ||
rxQueue: freertos.StaticQueue(txferElement, 1), | ||
//spiDrvHandle: c.SPIDRV_HandleData_t, | ||
|
||
fn recieve_callback(handle: c.SPIDRV_HandleData_t, buffer: []u8, n: usize) callconv(.C) void { | ||
var xHigherPriorityTaskWoken: freertos.BaseType_t = freertos.pdFALSE; | ||
const transfer_status_information = txferElement{ .status = c.ECODE_EMDRV_SPIDRV_OK, .items = n }; | ||
|
||
// self.xQueueSendFromISR(&transfer_status_information, &xHigherPriorityTaskWoken); | ||
|
||
freertos.portYIELD_FROM_ISR(xHigherPriorityTaskWoken); | ||
} | ||
fn send_callback(handle: c.SPIDRV_HandleData_t, buffer: []u8, n: usize) callconv(.C) void { | ||
var xHigherPriorityTaskWoken: freertos.BaseType_t = freertos.pdFALSE; | ||
const transfer_status_information = txferElement{ .status = c.ECODE_EMDRV_SPIDRV_OK, .items = n }; | ||
|
||
// self.xQueueSendFromISR(&transfer_status_information, &xHigherPriorityTaskWoken); | ||
|
||
freertos.portYIELD_FROM_ISR(xHigherPriorityTaskWoken); | ||
} | ||
|
||
pub fn init(self: *@This(), spiDrvHandle: c.SPIDRV_HandleData_t) void { | ||
//self.spidrvHandle = spiDrvHandle; | ||
//self.txQueue = freertos.StaticQueue(txferElement, 1); | ||
//self.rxQueue = freertos.StaticQueue(txferElement, 1); | ||
} | ||
pub fn deinit(self: *@This()) void { | ||
//self.txQueue.deinit(); | ||
//self.rxQueue.deinit(); | ||
} | ||
|
||
pub fn send(self: *@This(), data: []const u8, timeout_ticks: ?u32) !usize { | ||
var itemsTransfered: usize = 0; | ||
|
||
const spiEcode = c.SPIDRV_MTransmit(&self.spiDrvHandle, @ptrCast(data.ptr), @intCast(data.len), send_callback); | ||
if (spiEcode == c.ECODE_EMDRV_SPIDRV_OK) { | ||
if (self.txQueue.receive(timeout_ticks)) |val| { | ||
if (val.status == c.ECODE_EMDRV_SPIDRV_OK) { | ||
itemsTransfered = val.items; | ||
} | ||
} else |err| { | ||
return err; | ||
} | ||
} | ||
return itemsTransfered; | ||
} | ||
pub fn receive(self: *@This(), data: []u8, timeout_ticks: ?u32) ![]u8 { | ||
var itemsTransfered: usize = 0; | ||
|
||
const spiEcode = c.SPIDRV_MReceive(&self.spiDrvHandle, @ptrCast(data.ptr), @intCast(data.len), recieve_callback); | ||
if (spiEcode == c.ECODE_EMDRV_SPIDRV_OK) { | ||
if (self.rxQueue.receive(timeout_ticks)) |val| { | ||
if (val.status == c.ECODE_EMDRV_SPIDRV_OK) { | ||
itemsTransfered = val.items; | ||
} | ||
} else |err| { | ||
return err; | ||
} | ||
} | ||
return data[0..itemsTransfered]; | ||
} | ||
}; | ||
} |