Skip to content

Commit

Permalink
improved to use multibyte transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
odinthenerd committed Nov 4, 2021
1 parent 251931c commit 0a95714
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 65 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,38 +640,39 @@ you specific needs.
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23X17</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941">MCP7941</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
</tr>
</table>
Expand Down
10 changes: 4 additions & 6 deletions src/modm/driver/rtc/mcp7941.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ struct mcp7941
friend class Mcp7941;

public:
DateTime getDateTime(){
constexpr DateTime getDateTime(){
return date_time;
}
private:
uint8_t data[2];
DateTime date_time;
};
uint8_t scratch[8];
};

/**
Expand All @@ -72,13 +72,11 @@ class Mcp7941 : public mcp7941,
inline Data&
getData();

inline modm::ResumableResult<DateTime>
inline modm::ResumableResult<bool>
getDateTime();

inline modm::ResumableResult<bool>
setDateTime(DateTime);


setDateTime(DateTime);

private:
mcp7941::Data &data;
Expand Down
2 changes: 1 addition & 1 deletion src/modm/driver/rtc/mcp7941.lb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def prepare(module, options):
module.depends(
":architecture:i2c.device",
":architecture:register",
":processing:protothread")
":processing:resumable")
return True


Expand Down
75 changes: 22 additions & 53 deletions src/modm/driver/rtc/mcp7941_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,38 @@ template < typename I2cMaster >
modm::mcp7941::Data&
modm::Mcp7941<I2cMaster>::getData()
{
return reinterpret_cast<Data&>(this->data);
return this->data;
}

template < typename I2cMaster >
inline modm::ResumableResult<modm::mcp7941::DateTime>
inline modm::ResumableResult<bool>
modm::Mcp7941<I2cMaster>::getDateTime(){
RF_BEGIN();
this->transaction.configureWriteRead(&addr_seconds, 1, data.data, 1);
RF_CALL(this->runTransaction());
data.date_time.seconds = data.data[0];
this->transaction.configureWriteRead(&addr_minutes, 1, data.data, 1);
RF_CALL(this->runTransaction());
data.date_time.minutes = data.data[0];
this->transaction.configureWriteRead(&addr_hours, 1, data.data, 1);
RF_CALL(this->runTransaction());
data.date_time.hours = data.data[0];
this->transaction.configureWriteRead(&addr_days, 1, data.data, 1);
RF_CALL(this->runTransaction());
data.date_time.days = data.data[0];
this->transaction.configureWriteRead(&addr_months, 1, data.data, 1);
RF_CALL(this->runTransaction());
data.date_time.months = data.data[0];
this->transaction.configureWriteRead(&addr_years, 1, data.data, 1);
RF_CALL(this->runTransaction());
data.date_time.years = data.data[0];

RF_END_RETURN(data.date_time);
this->transaction.configureWriteRead(&addr_seconds, 1, scratch, 7);
if(RF_CALL(this->runTransaction())){
data.date_time.seconds = scratch[0];
data.date_time.seconds = scratch[1];
data.date_time.minutes = scratch[2];
data.date_time.hours = scratch[3];
data.date_time.days = scratch[4];
data.date_time.months = scratch[5];
data.date_time.years = scratch[6];
}
RF_END_RETURN(true);
}

template < typename I2cMaster >
inline modm::ResumableResult<bool>
modm::Mcp7941<I2cMaster>::setDateTime(mcp7941::DateTime dt){
RF_BEGIN();
data.data[0] = addr_seconds;
data.data[1] = dt.seconds;
this->transaction.configureWrite(data.data, 2);
RF_CALL(this->runTransaction());

data.data[0] = addr_minutes;
data.data[1] = dt.minutes;
this->transaction.configureWrite(data.data, 2);
RF_CALL(this->runTransaction());

data.data[0] = addr_hours;
data.data[1] = dt.hours;
this->transaction.configureWrite(data.data, 2);
RF_CALL(this->runTransaction());

data.data[0] = addr_days;
data.data[1] = dt.days;
this->transaction.configureWrite(data.data, 2);
RF_CALL(this->runTransaction());

data.data[0] = addr_months;
data.data[1] = dt.months;
this->transaction.configureWrite(data.data, 2);
RF_CALL(this->runTransaction());

data.data[0] = addr_years;
data.data[1] = dt.years;
this->transaction.configureWrite(data.data, 2);
RF_CALL(this->runTransaction());

RF_END_RETURN(true);
scratch[0] = addr_seconds;
scratch[1] = dt.seconds;
scratch[2] = dt.minutes;
scratch[3] = dt.hours;
scratch[4] = dt.days;
scratch[5] = dt.months;
scratch[6] = dt.years;
this->transaction.configureWrite(scratch, 7);
RF_END_RETURN_CALL(this->runTransaction());
}

0 comments on commit 0a95714

Please sign in to comment.