Skip to content

Commit

Permalink
Merge pull request #20 from piodabro/hw/hb5808_support
Browse files Browse the repository at this point in the history
Hw/hb5808 support
  • Loading branch information
piodabro authored Feb 8, 2018
2 parents e61a346 + f7383fc commit b9efa4f
Show file tree
Hide file tree
Showing 32 changed files with 1,743 additions and 441 deletions.
254 changes: 247 additions & 7 deletions PRO58/.cproject

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions PRO58/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/Release/
/obj/
user_env.mk
/Debug HB5808/
/Release_HB5808/
24 changes: 24 additions & 0 deletions PRO58/.settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,28 @@
</provider>
</extension>
</configuration>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.debug.239771716.1496360277" name="Debug_HB5808">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="1093063980346317110" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="fr.ac6.managedbuild.config.gnu.cross.exe.release.1829076308.613354538" name="Release_HB5808">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="1093063980346317110" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
182 changes: 182 additions & 0 deletions PRO58/Inc/eeprom_emulated.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef EEPROM_EMULATED_H_
#define EEPROM_EMULATED_H_

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

#pragma GCC push_options
#pragma GCC optimize ("O0")

/* Exported constants --------------------------------------------------------*/
/* Define the STM32F10Xxx Flash page size depending on the used STM32 device */
#define PAGE_SIZE FLASH_PAGE_SIZE /* Page size = 1KByte */

/* EEPROM start address in Flash */
#define EEPROM_START_ADDRESS ((uint32_t)0x0800F000U) /* EEPROM emulation start address:
after 60KByte of used Flash memory */

/* Pages 0 and 1 base and end addresses */
#define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x000U))
#define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))

#define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + PAGE_SIZE))
#define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))

/* Used Flash pages for EEPROM emulation */
#define PAGE0 ((uint16_t)0x0000)
#define PAGE1 ((uint16_t)0x0001)

/* No valid page define */
#define NO_VALID_PAGE ((uint16_t)0x00AB)

/* Page status definitions */
#define ERASED ((uint16_t)0xFFFF) /* PAGE is empty */
#define RECEIVE_DATA ((uint16_t)0xEEEE) /* PAGE is marked to receive data */
#define VALID_PAGE ((uint16_t)0x0000) /* PAGE containing valid data */

/* Valid pages in read and write defines */
#define READ_FROM_VALID_PAGE ((uint8_t)0x00)
#define WRITE_IN_VALID_PAGE ((uint8_t)0x01)

/* Page full define */
#define PAGE_FULL ((uint8_t)0x80)

/* Variables' number */
//#define NumbOfVar ((uint8_t)0x03)

/* Exported types ------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
uint16_t EE_Init(void);
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);


#define E2END 255

struct EERef{

EERef( const int index )
: index( index ) {}

//Access/read members.
uint16_t operator*() const {
uint16_t data;
EE_ReadVariable(index, &data);
return data;
}
operator const uint16_t() const { return **this; }

//Assignment/write members.
EERef &operator=( const EERef &ref ) { return *this = *ref; }
EERef &operator=( uint16_t in ) {
EE_WriteVariable(index, in);
return *this;
}
EERef &operator +=( uint16_t in ) { return *this = **this + in; }
EERef &operator -=( uint16_t in ) { return *this = **this - in; }
EERef &operator *=( uint16_t in ) { return *this = **this * in; }
EERef &operator /=( uint16_t in ) { return *this = **this / in; }
EERef &operator ^=( uint16_t in ) { return *this = **this ^ in; }
EERef &operator %=( uint16_t in ) { return *this = **this % in; }
EERef &operator &=( uint16_t in ) { return *this = **this & in; }
EERef &operator |=( uint16_t in ) { return *this = **this | in; }
EERef &operator <<=( uint16_t in ) { return *this = **this << in; }
EERef &operator >>=( uint16_t in ) { return *this = **this >> in; }

EERef &update( uint16_t in ) { return in != *this ? *this = in : *this; }

/** Prefix increment/decrement **/
EERef& operator++() { return *this += 1; }
EERef& operator--() { return *this -= 1; }

/** Postfix increment/decrement **/
uint16_t operator++ (int){
uint16_t ret = **this;
return ++(*this), ret;
}

uint16_t operator-- (int){
uint16_t ret = **this;
return --(*this), ret;
}

int index; //Index of current EEPROM cell.
};

/***
EEPtr class.
This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
Just like a normal pointer type, this can be dereferenced and repositioned using
increment/decrement operators.
***/

struct EEPtr{

EEPtr( const int index )
: index( index ) {}

operator const int() const { return index; }
EEPtr &operator=( int in ) { return index = in, *this; }

//Iterator functionality.
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
EERef operator*() { return index; }

/** Prefix & Postfix increment/decrement **/
EEPtr& operator++() { return ++index, *this; }
EEPtr& operator--() { return --index, *this; }
EEPtr operator++ (int) { return index++; }
EEPtr operator-- (int) { return index--; }

int index; //Index of current EEPROM cell.
};

/***
EEPROMClass class.
This object represents the entire EEPROM space.
It wraps the functionality of EEPtr and EERef into a basic interface.
It comes from Arduino...
***/
struct EEPROMClass{

//Basic user access methods.
EERef operator[]( const int idx ) { return idx; }
uint16_t read( int idx ) { return EERef( idx ); }
void write( int idx, uint16_t val ) { (EERef( idx )) = val; }
void update( int idx, uint16_t val ) { EERef( idx ).update( val ); }

//STL and C++11 iteration capability.
EEPtr begin() { return 0x00; }
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
uint16_t length() { return E2END + 1; }

//Functionality to 'get' and 'put' objects to and from EEPROM.
template< typename T > T &get( int idx, T &t ){
EEPtr e = idx;
uint16_t *ptr = (uint16_t*) &t;
int cnt = (sizeof(T) % 2 == 0) ? sizeof(T)/2 : sizeof(T)/2 + 1;
for( int count = cnt ; count ; --count, ++e ) *ptr++ = *e;
return t;
}

template< typename T > const T &put( int idx, const T &t ){
EEPtr e = idx;
const uint16_t *ptr = (const uint16_t*) &t;
int cnt = (sizeof(T) % 2 == 0) ? sizeof(T)/2 : sizeof(T)/2 + 1;
for( int count = cnt ; count ; --count, ++e ) (*e).update( *ptr++ );
return t;
}
};

static EEPROMClass EEPROM;


#pragma GCC pop_options

#endif /* EEPROM_EMULATED_H_ */
//

128 changes: 128 additions & 0 deletions PRO58/Inc/eeprom_external.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* external_eeprom.h
*
* Created on: 06.02.2018
* Author: PDabrowski
*/

#ifndef EEPROM_H_
#define EEPROM_H_

#include "Eeprom24C01_02.h"

extern Eeprom24C01_02 eep;

#define E2END 255

struct EERef{

EERef( const int index )
: index( index ) {}

//Access/read members.
uint8_t operator*() const { return eep.readByte( index ); }
operator const uint8_t() const { return **this; }

//Assignment/write members.
EERef &operator=( const EERef &ref ) { return *this = *ref; }
EERef &operator=( uint8_t in ) { return eep.writeByte( index, in ), *this; }
EERef &operator +=( uint8_t in ) { return *this = **this + in; }
EERef &operator -=( uint8_t in ) { return *this = **this - in; }
EERef &operator *=( uint8_t in ) { return *this = **this * in; }
EERef &operator /=( uint8_t in ) { return *this = **this / in; }
EERef &operator ^=( uint8_t in ) { return *this = **this ^ in; }
EERef &operator %=( uint8_t in ) { return *this = **this % in; }
EERef &operator &=( uint8_t in ) { return *this = **this & in; }
EERef &operator |=( uint8_t in ) { return *this = **this | in; }
EERef &operator <<=( uint8_t in ) { return *this = **this << in; }
EERef &operator >>=( uint8_t in ) { return *this = **this >> in; }

EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; }

/** Prefix increment/decrement **/
EERef& operator++() { return *this += 1; }
EERef& operator--() { return *this -= 1; }

/** Postfix increment/decrement **/
uint8_t operator++ (int){
uint8_t ret = **this;
return ++(*this), ret;
}

uint8_t operator-- (int){
uint8_t ret = **this;
return --(*this), ret;
}

int index; //Index of current EEPROM cell.
};

/***
EEPtr class.
This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
Just like a normal pointer type, this can be dereferenced and repositioned using
increment/decrement operators.
***/

struct EEPtr{

EEPtr( const int index )
: index( index ) {}

operator const int() const { return index; }
EEPtr &operator=( int in ) { return index = in, *this; }

//Iterator functionality.
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
EERef operator*() { return index; }

/** Prefix & Postfix increment/decrement **/
EEPtr& operator++() { return ++index, *this; }
EEPtr& operator--() { return --index, *this; }
EEPtr operator++ (int) { return index++; }
EEPtr operator-- (int) { return index--; }

int index; //Index of current EEPROM cell.
};

/***
EEPROMClass class.
This object represents the entire EEPROM space.
It wraps the functionality of EEPtr and EERef into a basic interface.
It comes from Arduino...
***/

struct EEPROMClass{

//Basic user access methods.
EERef operator[]( const int idx ) { return idx; }
uint8_t read( int idx ) { return EERef( idx ); }
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }

//STL and C++11 iteration capability.
EEPtr begin() { return 0x00; }
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
uint16_t length() { return E2END + 1; }

//Functionality to 'get' and 'put' objects to and from EEPROM.
template< typename T > T &get( int idx, T &t ){
EEPtr e = idx;
uint8_t *ptr = (uint8_t*) &t;
for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
return t;
}

template< typename T > const T &put( int idx, const T &t ){
EEPtr e = idx;
const uint8_t *ptr = (const uint8_t*) &t;
for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
return t;
}
};

static EEPROMClass EEPROM;

#endif /* EEPROM_H_ */
Loading

0 comments on commit b9efa4f

Please sign in to comment.