Continued work on MAX5715. MACRO functions are done, mostly tested in logic analyzer. SPI unable to work with hardware SS, so software SS is used instead
Added UART3 on PB10/PB11 for terminal (future use) git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@225 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.1239482633" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.option.debugging.level.1951365338" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.option.include.paths.35161744" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/hsb-mrts/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x}""/>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<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 class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1404919128665" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-103770239591" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
@@ -16,7 +16,7 @@
|
||||
<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 class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1404919128665" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-103770239591" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
||||
@@ -32,45 +32,101 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "spi.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
#define MAX5715_NUMBER_OF_DACS (4)
|
||||
|
||||
#define MAX5715_SEL_DACA (0x0)
|
||||
#define MAX5715_SEL_DACB (0x1)
|
||||
#define MAX5715_SEL_DACC (0x2)
|
||||
#define MAX5715_SEL_DACD (0x4)
|
||||
#define MAX5715_SPI_MAX_CLK_HZ (50000000)
|
||||
// SPI settings
|
||||
#define MAX5715_SPI_Direction (SPI_Direction_1Line_Tx)
|
||||
#define MAX5715_SPI_Mode (SPI_Mode_Master)
|
||||
#define MAX5715_SPI_DataSize (SPI_DataSize_8b)
|
||||
#define MAX5715_SPI_CPOL (SPI_CPOL_Low)
|
||||
#define MAX5715_SPI_CPHA (SPI_CPHA_1Edge)
|
||||
#define MAX5715_SPI_NSS (SPI_NSS_Soft)
|
||||
#define MAX5715_SPI_NSS_INTERNAL (SPI_NSSInternalSoft_Reset)
|
||||
#define MAX5715_SPI_FirstBit (SPI_FirstBit_MSB)
|
||||
#define MAX5715_SPI_CRCPolynomial (7)
|
||||
#define MAX5715_SPI_RX_QUEUE (1)
|
||||
#define MAX5715_SPI_TX_QUEUE (32)
|
||||
|
||||
#define MAX5715_CMD_CODEn (0x00)
|
||||
#define MAX5715_CMD_LOADn (0x10)
|
||||
#define MAX5715_CMD_CODEn_LOAD_ALL (0x20)
|
||||
#define MAX5715_CMD_CODEn_LOADn (0x30)
|
||||
#define MAX5715_CMD_POWER_NORMAL (0x40)
|
||||
#define MAX5715_CMD_POWER_PD1K (0x41)
|
||||
#define MAX5715_CMD_POWER_PD100K (0x42)
|
||||
#define MAX5715_CMD_POWER_HIGHZ (0x43)
|
||||
#define MAX5715_CMD_SW_CLEAR (0x50)
|
||||
#define MAX5715_CMD_SW_RESET (0x51)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_ON (0x60)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_OFF (0x61)
|
||||
#define MAX5715_CMD_REF_DAC_EXT (0x70)
|
||||
#define MAX5715_CMD_REF_DAC_2V5 (0x71)
|
||||
#define MAX5715_CMD_REF_DAC_2V0 (0x72)
|
||||
#define MAX5715_CMD_REF_DAC_4V0 (0x73)
|
||||
#define MAX5715_CMD_REF_ON_EXT (0x74)
|
||||
#define MAX5715_CMD_REF_ON_2V5 (0x75)
|
||||
#define MAX5715_CMD_REF_ON_2V0 (0x76)
|
||||
#define MAX5715_CMD_REF_ON_4V0 (0x77)
|
||||
#define MAX5715_CMD_CODE_ALL (0x80)
|
||||
#define MAX5715_CMD_LOAD_ALL (0x81)
|
||||
#define MAX5715_CMD_CODE_ALL_LOAD_ALL (0x82)
|
||||
#define MAX5715_SEL_DACA (0x1)
|
||||
#define MAX5715_SEL_DACB (0x2)
|
||||
#define MAX5715_SEL_DACC (0x4)
|
||||
#define MAX5715_SEL_DACD (0x8)
|
||||
|
||||
#define MAX5715_CMD_CODEn (0x00)
|
||||
#define MAX5715_CMD_LOADn (0x10)
|
||||
#define MAX5715_CMD_CODEn_LOAD_ALL (0x20)
|
||||
#define MAX5715_CMD_CODEn_LOADn (0x30)
|
||||
#define MAX5715_CMD_POWER_NORMAL (0x40)
|
||||
#define MAX5715_CMD_POWER_PD1K (0x41)
|
||||
#define MAX5715_CMD_POWER_PD100K (0x42)
|
||||
#define MAX5715_CMD_POWER_HIGHZ (0x43)
|
||||
#define MAX5715_CMD_SW_CLEAR (0x50)
|
||||
#define MAX5715_CMD_SW_RESET (0x51)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_ON (0x60)
|
||||
#define MAX5715_CMD_CONFIG_LATCH_OFF (0x61)
|
||||
#define MAX5715_CMD_REF_DAC_EXT (0x70)
|
||||
#define MAX5715_CMD_REF_DAC_2V5 (0x71)
|
||||
#define MAX5715_CMD_REF_DAC_2V0 (0x72)
|
||||
#define MAX5715_CMD_REF_DAC_4V0 (0x73)
|
||||
#define MAX5715_CMD_REF_ON_EXT (0x74)
|
||||
#define MAX5715_CMD_REF_ON_2V5 (0x75)
|
||||
#define MAX5715_CMD_REF_ON_2V0 (0x76)
|
||||
#define MAX5715_CMD_REF_ON_4V0 (0x77)
|
||||
#define MAX5715_CMD_CODE_ALL (0x80)
|
||||
#define MAX5715_CMD_LOAD_ALL (0x81)
|
||||
#define MAX5715_CMD_CODE_ALL_LOAD_ALL (0x82)
|
||||
|
||||
|
||||
#define MAX5715_writeCODEn(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn | (0x0F & DAC)), DATA))
|
||||
#define MAX5715_writeLOADn(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_LOADn | (0x0F & DAC)), 0x0000))
|
||||
#define MAX5715_writeCODEnLOADALL(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn_LOAD_ALL | (0x0F & DAC)), DATA))
|
||||
#define MAX5715_writeCODEnLOADn(self, DAC, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODEn_LOADn | (0x0F & DAC)), DATA))
|
||||
|
||||
#define MAX5715_writePOWER_NORMAL(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_NORMAL), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writePOWER_PD1K(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_PD1K), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writePOWER_PD100K(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_PD100K), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writePOWER_HIGHZ(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_POWER_HIGHZ), (0x00FF & (DAC << 4))))
|
||||
|
||||
#define MAX5715_writeSW_CLEAR(self) (MAX5715_sendCommand(self, (MAX5715_CMD_SW_CLEAR), 0x0000))
|
||||
#define MAX5715_writeSW_RESET(self) (MAX5715_sendCommand(self, (MAX5715_CMD_SW_RESET), 0x0000))
|
||||
|
||||
#define MAX5715_writeCONFIG_LATCH_ON(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_CONFIG_LATCH_ON), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeCONFIG_LATCH_OFF(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_CONFIG_LATCH_OFF), (0x00FF & (DAC << 4))))
|
||||
|
||||
#define MAX5715_writeREF_DAC_EXT(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_EXT), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_DAC_2V5(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_2V5), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_DAC_2V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_2V0), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_DAC_4V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_DAC_4V0), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_EXT(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_EXT), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_2V5(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_2V5), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_2V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_2V0), (0x00FF & (DAC << 4))))
|
||||
#define MAX5715_writeREF_ON_4V0(self, DAC) (MAX5715_sendCommand(self, (MAX5715_CMD_REF_ON_4V0), (0x00FF & (DAC << 4))))
|
||||
|
||||
#define MAX5715_writeCODE_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODE_ALL), DATA))
|
||||
#define MAX5715_writeLOAD_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_LOAD_ALL), 0x0000))
|
||||
#define MAX5715_writeCODE_ALL_LOAD_ALL(self, DATA) (MAX5715_sendCommand(self, (MAX5715_CMD_CODE_ALL_LOAD_ALL), DATA))
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct MAX5715_DAC
|
||||
{
|
||||
uint8_t id;
|
||||
uint16_t value;
|
||||
};
|
||||
|
||||
struct MAX5715
|
||||
{
|
||||
const struct IODevice* device;
|
||||
struct MAX5715_DAC dac[MAX5715_NUMBER_OF_DACS];
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
@@ -79,15 +135,79 @@
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_construct
|
||||
* Description of function
|
||||
* Constructs the MAX5715 instance into argument self.
|
||||
*
|
||||
* @param self
|
||||
* @param self The MAX5715 object to initialize
|
||||
* @param device The IODevice that should be used for
|
||||
* communication with the MAX5715
|
||||
*
|
||||
* @return ErrorStatus
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715_construct(const struct IODevice* self, para2_name);
|
||||
extern ErrorStatus MAX5715_construct(struct MAX5715* self, const struct IODevice* device);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_destruct
|
||||
* Destructs the MAX5715 instance in argument self
|
||||
*
|
||||
* @param self
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void MAX5715_destruct(struct MAX5715* self);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_getSpiParameters
|
||||
* Returns a filled-in struct SpiParameters with the MAX5715-specific parameters
|
||||
*
|
||||
* @param parameters SpiParameters struct to fill
|
||||
*
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715_getSpiParameters(struct SpiParameters* parameters);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715_sendCommand
|
||||
* Sends a command to MAX5715 instance in argument self with the command in
|
||||
* argument command
|
||||
*
|
||||
* @param self The MAX5715 instance
|
||||
* @param command The command to be sent
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715_sendCommand(const struct MAX5715* self, uint8_t command, uint16_t data);
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* MAX5715DAC_setOutput
|
||||
* Sets the output of the DAC in argument self to the value given in argument
|
||||
* value
|
||||
*
|
||||
* @param self The DAC to use
|
||||
* @param value The value to set
|
||||
* @return ErrorStatus SUCCESS if initialisation was successful
|
||||
* ERROR otherwise
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus MAX5715DAC_setOutput(struct MAX5715_DAC self, uint16_t value);
|
||||
|
||||
#endif /* INC_MAX5715_H_ */
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#define NHD0420_SPI_CPOL (SPI_CPOL_High)
|
||||
#define NHD0420_SPI_CPHA (SPI_CPHA_2Edge)
|
||||
#define NHD0420_SPI_NSS (SPI_NSS_Soft)
|
||||
#define NHD0420_SPI_NSS_INTERNAL (SPI_NSSInternalSoft_Reset)
|
||||
#define NHD0420_SPI_FirstBit (SPI_FirstBit_MSB)
|
||||
#define NHD0420_SPI_CRCPolynomial (7)
|
||||
#define NHD0420_SPI_RX_QUEUE (32)
|
||||
@@ -115,7 +116,10 @@
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
struct NHD0420
|
||||
{
|
||||
const struct IODevice* device;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
@@ -134,7 +138,7 @@
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_construct(const struct IODevice* const device);
|
||||
extern ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* device);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -148,7 +152,7 @@ extern ErrorStatus NHD0420_construct(const struct IODevice* const device);
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void NHD0420_destruct(const struct IODevice* self);
|
||||
extern void NHD0420_destruct(struct NHD0420* self);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -178,7 +182,7 @@ extern ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters);
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_setCursorToPosition(const struct IODevice* self, char row, char column);
|
||||
extern ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, char row, char column);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -195,7 +199,7 @@ extern ErrorStatus NHD0420_setCursorToPosition(const struct IODevice* self, char
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_setContrast(const struct IODevice* self, char contrast);
|
||||
extern ErrorStatus NHD0420_setContrast(const struct NHD0420* self, char contrast);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -212,7 +216,7 @@ extern ErrorStatus NHD0420_setContrast(const struct IODevice* self, char contras
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_setBacklightBrightness(const struct IODevice* self, char brightness);
|
||||
extern ErrorStatus NHD0420_setBacklightBrightness(const struct NHD0420* self, char brightness);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -237,7 +241,7 @@ extern ErrorStatus NHD0420_setBacklightBrightness(const struct IODevice* self, c
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_setRS232Baudrate(const struct IODevice* self, char baudrate);
|
||||
extern ErrorStatus NHD0420_setRS232Baudrate(const struct NHD0420* self, char baudrate);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
@@ -263,7 +267,7 @@ extern ErrorStatus NHD0420_setRS232Baudrate(const struct IODevice* self, char ba
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_setI2CAddress(const struct IODevice* self, char address);
|
||||
extern ErrorStatus NHD0420_setI2CAddress(const struct NHD0420* self, char address);
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* NHD0420_SendCommand
|
||||
@@ -277,8 +281,8 @@ extern ErrorStatus NHD0420_setI2CAddress(const struct IODevice* self, char addre
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus NHD0420_sendCommand(const struct IODevice* self, char command);
|
||||
extern ErrorStatus NHD0420_sendCommand(const struct NHD0420* self, char command);
|
||||
|
||||
extern ErrorStatus NHD0420_sendData(const struct IODevice* self, const char* buffer, size_t length);
|
||||
extern ErrorStatus NHD0420_sendData(const struct NHD0420* self, const char* buffer, size_t length);
|
||||
|
||||
#endif /* DISPLAY_INC_NHD0420_H_ */
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
#include "MAX5715.h"
|
||||
|
||||
#include "spi.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
@@ -53,3 +57,83 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus MAX5715_construct(struct MAX5715* self, const struct IODevice* device)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
int loopCounter;
|
||||
if (self != NULL)
|
||||
{
|
||||
self->device = device;
|
||||
|
||||
for (loopCounter = 0; loopCounter < MAX5715_NUMBER_OF_DACS; loopCounter++)
|
||||
{
|
||||
self->dac[loopCounter].id = loopCounter;
|
||||
self->dac[loopCounter].value = 0x0000;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void MAX5715_destruct(struct MAX5715* self)
|
||||
{
|
||||
self->device = NULL;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus MAX5715_getSpiParameters(struct SpiParameters* parameters)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if ((configCPU_CLOCK_HZ / 2) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 4) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
|
||||
}
|
||||
else if ((configCPU_CLOCK_HZ / 8) < MAX5715_SPI_MAX_CLK_HZ)
|
||||
{
|
||||
parameters->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The CPU clock is too high. The pre-scaler has a max of 256. A clock higher than 25,6 MHz
|
||||
// results in a SPI CLK higher than 100 kHz, which is the max of the display
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
// SPI pre-scaler was no problem - assign the remaining parameters
|
||||
parameters->SPI_CPHA = MAX5715_SPI_CPHA;
|
||||
parameters->SPI_CPOL = MAX5715_SPI_CPOL;
|
||||
parameters->SPI_CRCPolynomial = MAX5715_SPI_CRCPolynomial;
|
||||
parameters->SPI_DataSize = MAX5715_SPI_DataSize;
|
||||
parameters->SPI_Direction = MAX5715_SPI_Direction;
|
||||
parameters->SPI_FirstBit = MAX5715_SPI_FirstBit;
|
||||
parameters->SPI_Mode = MAX5715_SPI_Mode;
|
||||
parameters->SPI_NSS = MAX5715_SPI_NSS;
|
||||
parameters->SPI_NSS_internal = MAX5715_SPI_NSS_INTERNAL;
|
||||
parameters->rxQueueSize = MAX5715_SPI_RX_QUEUE;
|
||||
parameters->txQueueSize = MAX5715_SPI_TX_QUEUE;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus MAX5715_sendCommand(const struct MAX5715* self, uint8_t command, uint16_t data)
|
||||
{
|
||||
char buffer[3] = {(char)command, (char)(data >> 4), (char)((data << 4) & 0x00F0)};
|
||||
|
||||
return IODevice_write(self->device, buffer, 3);
|
||||
}
|
||||
|
||||
@@ -70,17 +70,26 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
ErrorStatus NHD0420_construct(const struct IODevice* const device)
|
||||
ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* device)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if (self->device == NULL)
|
||||
{
|
||||
self->device = device;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void NHD0420_destruct (const struct IODevice* self)
|
||||
void NHD0420_destruct (struct NHD0420* self)
|
||||
{
|
||||
|
||||
self->device = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +127,7 @@ ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
||||
parameters->SPI_FirstBit = NHD0420_SPI_FirstBit;
|
||||
parameters->SPI_Mode = NHD0420_SPI_Mode;
|
||||
parameters->SPI_NSS = NHD0420_SPI_NSS;
|
||||
parameters->SPI_NSS_internal = NHD0420_SPI_NSS_INTERNAL;
|
||||
parameters->rxQueueSize = NHD0420_SPI_RX_QUEUE;
|
||||
parameters->txQueueSize = NHD0420_SPI_TX_QUEUE;
|
||||
}
|
||||
@@ -127,7 +137,7 @@ ErrorStatus NHD0420_getSpiParameters(struct SpiParameters* parameters)
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setCursorToPosition(const struct IODevice* self, char row, char column)
|
||||
ErrorStatus NHD0420_setCursorToPosition(const struct NHD0420* self, char row, char column)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -157,7 +167,7 @@ ErrorStatus NHD0420_setCursorToPosition(const struct IODevice* self, char row, c
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setContrast(const struct IODevice* self, char contrast)
|
||||
ErrorStatus NHD0420_setContrast(const struct NHD0420* self, char contrast)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -183,7 +193,7 @@ ErrorStatus NHD0420_setContrast(const struct IODevice* self, char contrast)
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setBacklightBrightness(const struct IODevice* self, char brightness)
|
||||
ErrorStatus NHD0420_setBacklightBrightness(const struct NHD0420* self, char brightness)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -209,7 +219,7 @@ ErrorStatus NHD0420_setBacklightBrightness(const struct IODevice* self, char bri
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setRS232Baudrate(const struct IODevice* self, char baudrate)
|
||||
ErrorStatus NHD0420_setRS232Baudrate(const struct NHD0420* self, char baudrate)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -233,7 +243,7 @@ ErrorStatus NHD0420_setRS232Baudrate(const struct IODevice* self, char baudrate)
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_setI2CAddress(const struct IODevice* self, char address)
|
||||
ErrorStatus NHD0420_setI2CAddress(const struct NHD0420* self, char address)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
@@ -268,23 +278,23 @@ ErrorStatus NHD0420_setI2CAddress(const struct IODevice* self, char address)
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
ErrorStatus NHD0420_sendCommand(const struct IODevice* self, char command)
|
||||
ErrorStatus NHD0420_sendCommand(const struct NHD0420* self, char command)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
char buffer[NHD0420_CMD_LENGTH] = {NHD0420_CMD_PREFIX, command};
|
||||
|
||||
returnValue = IODevice_write(self, buffer, NHD0420_CMD_LENGTH);
|
||||
returnValue = IODevice_write(self->device, buffer, NHD0420_CMD_LENGTH);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
ErrorStatus NHD0420_sendData(const struct IODevice* self, const char* buffer, size_t length)
|
||||
ErrorStatus NHD0420_sendData(const struct NHD0420* self, const char* buffer, size_t length)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
returnValue = IODevice_write(self, buffer, length);
|
||||
returnValue = IODevice_write(self->device, buffer, length);
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user