
Example how to use DS28EC20 EEPROM with MaximInterface over GPIO
Dependencies: MaximInterface_Extended
Revision 1:62acf2e0179a, committed 2020-01-06
- Comitter:
- reARMnimator
- Date:
- Mon Jan 06 15:55:11 2020 +0000
- Parent:
- 0:476a6e04dc69
- Commit message:
- Fixed some build issues.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximInterface.lib Mon Jan 06 15:55:11 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/reARMnimator/code/MaximInterface_Extended/#de4b8812877d
--- a/MaximInterface_Extended.lib Thu Jan 02 11:56:51 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/reARMnimator/code/MaximInterface_Extended/#aeda90624ad0
--- a/main.cpp Thu Jan 02 11:56:51 2020 +0000 +++ b/main.cpp Mon Jan 06 15:55:11 2020 +0000 @@ -4,69 +4,101 @@ #include "MaximInterface/Devices/DS28EC20.hpp" DigitalOut myled(LED1); -#define CONFIG_OW_PIN_NAME P1_1 +#define CONFIG_OW_PIN_NAME PinName::PA_1 + +class Sleep : public MaximInterface::Sleep +{ +public: + virtual void invoke (int ms) const + { + uint32_t ticks = (ms * 1000u) / osKernelGetTickFreq(); + osDelay(ticks); + return; + } -class SelectOverdriveSkipRom { - public: - typedef MaximInterface::SelectRom::argument_type argument_type; - typedef MaximInterface::SelectRom::result_type result_type; + virtual ~Sleep(void) + { + return; + }; +}; - explicit SelectOverdriveSkipRom(MaximInterface::RomId::const_span romId) { setRomId(romId); } +static Sleep sleepObj; - MaximInterface::RomId::const_span romId() const { return romId_; } +class SelectOverdriveSkipRom +{ +public: + typedef MaximInterface::SelectRom::argument_type argument_type; + typedef MaximInterface::SelectRom::result_type result_type; - void setRomId(MaximInterface::RomId::const_span romId) { MaximInterface::copy(romId, MaximInterface::make_span(romId_)); } + explicit SelectOverdriveSkipRom(MaximInterface::RomId::const_span romId) + { + setRomId(romId); + } + + MaximInterface::RomId::const_span romId() const + { + return romId_; + } - MaximInterface_EXPORT MaximInterface::error_code operator()(MaximInterface::OneWireMaster & master) const - { + void setRomId(MaximInterface::RomId::const_span romId) + { + MaximInterface::copy(romId, MaximInterface::make_span(romId_)); + } + + MaximInterface_EXPORT MaximInterface::error_code operator()(MaximInterface::OneWireMaster & master) const + { #if 0 - return MaximInterface::skipRom(master); + return MaximInterface::skipRom(master); #else - return MaximInterface::overdriveSkipRom(master); + return MaximInterface::overdriveSkipRom(master); #endif - } + } - private: - MaximInterface::RomId::array romId_; +private: + MaximInterface::RomId::array romId_; }; -int main() { - MaximInterface::GpioOneWireMaster *p_GPIO_OW_Master = new (std::nothrow) MaximInterface::GpioOneWireMaster(CONFIG_OW_PIN_NAME); +int main() +{ + MaximInterface::GpioOneWireMaster *p_GPIO_OW_Master = new (std::nothrow) MaximInterface::GpioOneWireMaster(CONFIG_OW_PIN_NAME); MaximInterface::OneWireMaster &OW_Master(*p_GPIO_OW_Master); - MaximInterface::error_code err = OW_Master.initialize(); - + MaximInterface::error_code err = p_GPIO_OW_Master->initialize(); + MaximInterface::SearchRomState State; /* ... Fallback to standard speed after ID-chip has been powered off */ OW_Master.setSpeed(MaximInterface::OneWireMaster::StandardSpeed); - error = MaximInterface::searchRom(OW_Master, State); + err = MaximInterface::searchRom(OW_Master, State); - if (!error) { + if (!err) { if (familyCode(State.romId) == MaximInterface::DS28EC20::familyCode) { /* ... wait for 50 ms */ uint32_t Ticks = (50u * 1000u) / osKernelGetTickFreq(); osDelay(Ticks); - this->m_SelectRom.setRomId(State.romId); + SelectOverdriveSkipRom RomSelectorObject(State.romId); - MaximInterface::DS28EC20 *p_EEPROM = new (std::nothrow) MaximInterface::DS28EC20(OneWire_IDChip::m_SleepObj, OW_Master, MaximInterface::SelectRom(this->m_SelectRom), this->m_SelectRom.romId()); + MaximInterface::DS28EC20 *p_EEPROM = new (std::nothrow) MaximInterface::DS28EC20(sleepObj, OW_Master, MaximInterface::SelectRom(RomSelectorObject), RomSelectorObject.romId()); if (NULL != p_EEPROM) { - this->m_Size = MaximInterface::DS28EC20::memoryPages * MaximInterface::DS28EC20::pageSizeBytes; + size_t Size = MaximInterface::DS28EC20::memoryPages * MaximInterface::DS28EC20::pageSizeBytes; + MaximInterface::DS28EC20::Address Addr = static_cast<MaximInterface::DS28EC20::Address>(0); + size_t ActualLength = 32u; + uint8_t Buffer[32u] = {0}; + err = p_EEPROM->readMemoryExt(Addr, &Buffer[0], ActualLength); + err = MaximInterface::writeMemory(*p_EEPROM, Addr, &Buffer[0], ActualLength); } } } - err = this->mp_EEPROM->readMemoryExt(Addr, &Buffer[0], ActualLength); - err = MaximInterface::writeMemory(*(this->mp_EEPROM), Addr, &Buffer[0], ActualLength); while(1) { myled = 1; - wait(0.2); + wait_us(2000); myled = 0; - wait(0.2); + wait_us(2000); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Mon Jan 06 15:55:11 2020 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#bacf37894945a5c9b7619b709eeabeeb68d25d9c
--- a/mbed.bld Thu Jan 02 11:56:51 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file