amiro-os / components / FileSystemInputOutput / FSIOPowerManagement.cpp @ eef47799
History | View | Annotate | Download (1.78 KB)
1 | 58fe0e0b | Thomas Schöpping | #include <amiro/FileSystemInputOutput/FSIOPowerManagement.hpp> |
---|---|---|---|
2 | |||
3 | using namespace amiro; |
||
4 | using namespace amiro::fileSystemIo; |
||
5 | |||
6 | msg_t |
||
7 | FSIOPowerManagement:: |
||
8 | getVcnl4020Offset (uint16_t *buffer, uint8_t idx) { |
||
9 | |||
10 | msg_t bytesWritten = 0;
|
||
11 | const uint8_t bufferSize = sizeof(uint16_t); |
||
12 | |||
13 | // Check if the vcnl index is in a valid range
|
||
14 | if (idx >= sizeof(PowerManagement_1_1::vcnl4020offset)) { |
||
15 | return WRONG_INDEX;
|
||
16 | } |
||
17 | |||
18 | // Get the data out of the memory
|
||
19 | switch (this->BSMV) { |
||
20 | case 0x01u: |
||
21 | // Set the pointer to the address
|
||
22 | chFileStreamSeek((BaseFileStream*)&at24c01, offsetof(FSIOPowerManagement::PowerManagement_1_1, vcnl4020offset[idx])); |
||
23 | if (this->bsmv >= 0x01u) { |
||
24 | bytesWritten = chSequentialStreamRead((BaseFileStream*)&at24c01, (uint8_t*) buffer, bufferSize); |
||
25 | } else {
|
||
26 | return NOT_IMPLEMENTED;
|
||
27 | } |
||
28 | break;
|
||
29 | } |
||
30 | |||
31 | if (bytesWritten != bufferSize) {
|
||
32 | return IO_ERROR;
|
||
33 | } else {
|
||
34 | return OK;
|
||
35 | } |
||
36 | } |
||
37 | |||
38 | msg_t |
||
39 | FSIOPowerManagement:: |
||
40 | setVcnl4020Offset (uint16_t buffer, uint8_t idx) { |
||
41 | |||
42 | msg_t bytesWritten = 0;
|
||
43 | const uint8_t bufferSize = sizeof(uint16_t); |
||
44 | |||
45 | // Check if the vcnl index is in a valid range
|
||
46 | if (idx >= sizeof(PowerManagement_1_1::vcnl4020offset)) { |
||
47 | return WRONG_INDEX;
|
||
48 | } |
||
49 | |||
50 | // Get the data out of the memory
|
||
51 | switch (this->BSMV) { |
||
52 | case 0x01u: |
||
53 | // Set the pointer to the address
|
||
54 | chFileStreamSeek((BaseFileStream*)&at24c01, offsetof(FSIOPowerManagement::PowerManagement_1_1, vcnl4020offset[idx])); |
||
55 | if (this->bsmv >= 0x01u) { |
||
56 | bytesWritten = chSequentialStreamWrite((BaseFileStream*)&at24c01, (const uint8_t*) &buffer, bufferSize);
|
||
57 | } else {
|
||
58 | return NOT_IMPLEMENTED;
|
||
59 | } |
||
60 | break;
|
||
61 | } |
||
62 | |||
63 | if (bytesWritten != bufferSize) {
|
||
64 | return IO_ERROR;
|
||
65 | } else {
|
||
66 | return OK;
|
||
67 | } |
||
68 | } |