diff options
| author | Daniel Bevenius <[email protected]> | 2022-08-24 13:35:48 +0200 |
|---|---|---|
| committer | Daniel Bevenius <[email protected]> | 2022-08-25 15:40:14 +0200 |
| commit | f2ac14b86f21c31221bba1e1653e2a9020d60d8e (patch) | |
| tree | 4a2db095e2d3f4e2b0be55213fef6886fe24f670 /src/lib.rs | |
| parent | f76815d642064b5ed5b1673e4a386e2747813f20 (diff) | |
Add WORD_LENGTH_32/HIGH_SPEED constants
This commit adds two constants which are intended to be used for setting
the `Word Length` and `High Speed` fields in the gSPR register
(address: 0x0000, bit: 0 and bit 4).
Currently, this field is being set by the following line:
```rust
// 32bit, little endian.
self.write32_swapped(REG_BUS_CTRL, 0x00010031).await;
```
Assuming that we are sending these bits using the gSPI write protocol
and using 16-bit word operation in little endian (which I think might
be the default) then the data bytes should be packed like this:
```
+--+--+--+--+
|D1|D0|D3|D2|
+--+--+--+--+
val (hex): 0x00010031
val (bin): 00000000000000010000000000110001
rotated(16): 00000000001100010000000000000001
```
If we split val into bytes and rotated the bits we get:
```
Split into bytes:
D3 D2 D1 D0
00000000 00000001 00000000 00110001
Rotate 16 and split into bytes:
D1 D0 D3 D2
00000000 00110001 00000000 00000001
```
Looking at the write procotol it seems to me that the above will
indeed set the `Word Length` to 1 but will also set other values.
```
Status enable (1=default)
D1 D0 D3 D2 ↓
00000000 00110001 00000000 00000001
↑↑ ↑↑ ↑
|| |Word Length (1=32-bit)
|| |
|| Endianess (0=Little)
||
|High-speed mode (1=High speed (default))
|
Interrupt polarity (1=high (default))
```
This commit suggests adding the above mentioned constants for setting
the only the word length field and the high speed field.
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs index 3932ce41b..ef586c8f4 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -53,6 +53,8 @@ const REG_BUS_STATUS: u32 = 0x8; | |||
| 53 | const REG_BUS_FEEDBEAD: u32 = 0x14; | 53 | const REG_BUS_FEEDBEAD: u32 = 0x14; |
| 54 | const REG_BUS_TEST: u32 = 0x18; | 54 | const REG_BUS_TEST: u32 = 0x18; |
| 55 | const REG_BUS_RESP_DELAY: u32 = 0x1c; | 55 | const REG_BUS_RESP_DELAY: u32 = 0x1c; |
| 56 | const WORD_LENGTH_32: u32 = 0x1; | ||
| 57 | const HIGH_SPEED: u32 = 0x10; | ||
| 56 | 58 | ||
| 57 | // SPI_STATUS_REGISTER bits | 59 | // SPI_STATUS_REGISTER bits |
| 58 | const STATUS_DATA_NOT_AVAILABLE: u32 = 0x00000001; | 60 | const STATUS_DATA_NOT_AVAILABLE: u32 = 0x00000001; |
| @@ -570,8 +572,8 @@ where | |||
| 570 | let val = self.read32_swapped(REG_BUS_TEST).await; | 572 | let val = self.read32_swapped(REG_BUS_TEST).await; |
| 571 | assert_eq!(val, TEST_PATTERN); | 573 | assert_eq!(val, TEST_PATTERN); |
| 572 | 574 | ||
| 573 | // 32bit, little endian. | 575 | // 32-bit word length, little endian (which is the default endianess). |
| 574 | self.write32_swapped(REG_BUS_CTRL, 0x00010031).await; | 576 | self.write32_swapped(REG_BUS_CTRL, WORD_LENGTH_32 | HIGH_SPEED).await; |
| 575 | 577 | ||
| 576 | let val = self.read32(FUNC_BUS, REG_BUS_FEEDBEAD).await; | 578 | let val = self.read32(FUNC_BUS, REG_BUS_FEEDBEAD).await; |
| 577 | assert_eq!(val, FEEDBEAD); | 579 | assert_eq!(val, FEEDBEAD); |
