global: remove timers
This commit is contained in:
parent
84e50cdec7
commit
9608200f91
@ -41,14 +41,6 @@
|
|||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/inc}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/inc}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/inc}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/inc}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/inc}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/inc}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/inc}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/inc}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/inc}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/inc}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Timer/inc}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/SwitchController/inc}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/PressureWrapper/inc}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/SDP600Sensor/inc}""/>
|
|
||||||
</option>
|
</option>
|
||||||
<option id="com.crt.advproject.cpp.misc.dialect.1893636131" name="Language standard" superClass="com.crt.advproject.cpp.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.c++11" valueType="enumerated"/>
|
<option id="com.crt.advproject.cpp.misc.dialect.1893636131" name="Language standard" superClass="com.crt.advproject.cpp.misc.dialect" useByScannerDiscovery="true" value="com.crt.advproject.misc.dialect.c++11" valueType="enumerated"/>
|
||||||
<inputType id="com.crt.advproject.compiler.cpp.input.1024506123" superClass="com.crt.advproject.compiler.cpp.input"/>
|
<inputType id="com.crt.advproject.compiler.cpp.input.1024506123" superClass="com.crt.advproject.compiler.cpp.input"/>
|
||||||
@ -72,7 +64,6 @@
|
|||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.688644944" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.688644944" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/inc}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/inc}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/esp-vent-main}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/esp-vent-main}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/esp-vent-main/DigitalIoPin}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/inc}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/inc}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/inc}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/inc}""/>
|
||||||
</option>
|
</option>
|
||||||
@ -103,12 +94,12 @@
|
|||||||
</tool>
|
</tool>
|
||||||
<tool id="com.crt.advproject.link.cpp.exe.debug.1426626994" name="MCU C++ Linker" superClass="com.crt.advproject.link.cpp.exe.debug">
|
<tool id="com.crt.advproject.link.cpp.exe.debug.1426626994" name="MCU C++ Linker" superClass="com.crt.advproject.link.cpp.exe.debug">
|
||||||
<option id="com.crt.advproject.link.cpp.thumb.1194209702" name="Thumb mode" superClass="com.crt.advproject.link.cpp.thumb" value="true" valueType="boolean"/>
|
<option id="com.crt.advproject.link.cpp.thumb.1194209702" name="Thumb mode" superClass="com.crt.advproject.link.cpp.thumb" value="true" valueType="boolean"/>
|
||||||
<option id="com.crt.advproject.link.memory.load.image.cpp.1000848894" name="Plain load image" superClass="com.crt.advproject.link.memory.load.image.cpp" value="" valueType="string"/>
|
<option id="com.crt.advproject.link.memory.load.image.cpp.1000848894" name="Plain load image" superClass="com.crt.advproject.link.memory.load.image.cpp" useByScannerDiscovery="false" value="" valueType="string"/>
|
||||||
<option defaultValue="com.crt.advproject.heapAndStack.lpcXpressoStyle.cpp" id="com.crt.advproject.link.memory.heapAndStack.style.cpp.981260644" name="Heap and Stack placement" superClass="com.crt.advproject.link.memory.heapAndStack.style.cpp" valueType="enumerated"/>
|
<option defaultValue="com.crt.advproject.heapAndStack.lpcXpressoStyle.cpp" id="com.crt.advproject.link.memory.heapAndStack.style.cpp.981260644" name="Heap and Stack placement" superClass="com.crt.advproject.link.memory.heapAndStack.style.cpp" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||||
<option id="com.crt.advproject.link.memory.heapAndStack.cpp.547910715" name="Heap and Stack options" superClass="com.crt.advproject.link.memory.heapAndStack.cpp" value="&Heap:Default;Post Data;Default&Stack:Default;End;Default" valueType="string"/>
|
<option id="com.crt.advproject.link.memory.heapAndStack.cpp.547910715" name="Heap and Stack options" superClass="com.crt.advproject.link.memory.heapAndStack.cpp" value="&Heap:Default;Post Data;Default&Stack:Default;End;Default" valueType="string"/>
|
||||||
<option id="com.crt.advproject.link.memory.data.cpp.479381724" name="Global data placement" superClass="com.crt.advproject.link.memory.data.cpp" value="" valueType="string"/>
|
<option id="com.crt.advproject.link.memory.data.cpp.479381724" name="Global data placement" superClass="com.crt.advproject.link.memory.data.cpp" useByScannerDiscovery="false" value="" valueType="string"/>
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.crt.advproject.link.memory.sections.cpp.1578166592" name="Extra linker script input sections" superClass="com.crt.advproject.link.memory.sections.cpp" valueType="stringList"/>
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.crt.advproject.link.memory.sections.cpp.1578166592" name="Extra linker script input sections" superClass="com.crt.advproject.link.memory.sections.cpp" useByScannerDiscovery="false" valueType="stringList"/>
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.crt.advproject.link.cpp.multicore.master.userobjs.10592627" name="Slave Objects (not visible)" superClass="com.crt.advproject.link.cpp.multicore.master.userobjs" valueType="userObjs"/>
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="com.crt.advproject.link.cpp.multicore.master.userobjs.10592627" name="Slave Objects (not visible)" superClass="com.crt.advproject.link.cpp.multicore.master.userobjs" useByScannerDiscovery="false" valueType="userObjs"/>
|
||||||
<option id="com.crt.advproject.link.cpp.multicore.slave.2071357873" name="Multicore configuration" superClass="com.crt.advproject.link.cpp.multicore.slave"/>
|
<option id="com.crt.advproject.link.cpp.multicore.slave.2071357873" name="Multicore configuration" superClass="com.crt.advproject.link.cpp.multicore.slave"/>
|
||||||
<option id="com.crt.advproject.link.cpp.arch.1780684898" name="Architecture" superClass="com.crt.advproject.link.cpp.arch" value="com.crt.advproject.link.cpp.target.cm3" valueType="enumerated"/>
|
<option id="com.crt.advproject.link.cpp.arch.1780684898" name="Architecture" superClass="com.crt.advproject.link.cpp.arch" value="com.crt.advproject.link.cpp.target.cm3" valueType="enumerated"/>
|
||||||
<option id="com.crt.advproject.link.cpp.script.853146968" name="Linker script" superClass="com.crt.advproject.link.cpp.script" value=""esp-vent-main_Debug.ld"" valueType="string"/>
|
<option id="com.crt.advproject.link.cpp.script.853146968" name="Linker script" superClass="com.crt.advproject.link.cpp.script" value=""esp-vent-main_Debug.ld"" valueType="string"/>
|
||||||
@ -128,14 +119,6 @@
|
|||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.paths.804461696" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.paths.804461696" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/Debug}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_board_nxp_lpcxpresso_1549/Debug}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/Debug}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/Debug}""/>
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/DigitalIoPin/Debug}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/LiquidCrystal/Debug}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/I2C/Debug}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/StateHandler/Debug}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Timer/Debug}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/SwitchController/Debug}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/PressureWrapper/Debug}""/>
|
|
||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/SDP600Sensor/Debug}""/>
|
|
||||||
</option>
|
</option>
|
||||||
<option id="com.crt.advproject.link.cpp.crpenable.8641361" name="Enable automatic placement of Code Read Protection field in image" superClass="com.crt.advproject.link.cpp.crpenable"/>
|
<option id="com.crt.advproject.link.cpp.crpenable.8641361" name="Enable automatic placement of Code Read Protection field in image" superClass="com.crt.advproject.link.cpp.crpenable"/>
|
||||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.849613399" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.849613399" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||||
|
|||||||
@ -15,7 +15,7 @@ struct I2C_config {
|
|||||||
unsigned int speed;
|
unsigned int speed;
|
||||||
unsigned int clock_divider;
|
unsigned int clock_divider;
|
||||||
unsigned int i2c_mode;
|
unsigned int i2c_mode;
|
||||||
I2C_config(): device_number(0), speed(100000), clock_divider(40), i2c_mode(IOCON_SFI2C_EN) {};
|
I2C_config(unsigned int dn, unsigned int sp, unsigned int cd): device_number(dn), speed(sp), clock_divider(cd), i2c_mode(IOCON_SFI2C_EN) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class I2C {
|
class I2C {
|
||||||
|
|||||||
@ -122,7 +122,7 @@ private:
|
|||||||
* weigh of fan, so voltage within range of 0-89 is not
|
* weigh of fan, so voltage within range of 0-89 is not
|
||||||
* sufficient to start motor.
|
* sufficient to start motor.
|
||||||
* TODO: Value 89 should be scaled to 0 at some point */
|
* TODO: Value 89 should be scaled to 0 at some point */
|
||||||
Counter fan_speed = { 20, 1000 };
|
Counter fan_speed = { 80, 1000 };
|
||||||
/*integral controller for PID. should be global, since it
|
/*integral controller for PID. should be global, since it
|
||||||
* accumulates error signals encountered since startup*/
|
* accumulates error signals encountered since startup*/
|
||||||
int integral = 0;
|
int integral = 0;
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
class SwitchController
|
class SwitchController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SwitchController (DigitalIoPin *button, Timer *timer, StateHandler *handler,
|
SwitchController (DigitalIoPin *button, StateHandler *handler,
|
||||||
int button_mode);
|
int button_mode);
|
||||||
virtual ~SwitchController ();
|
virtual ~SwitchController ();
|
||||||
/** Listen to switch button
|
/** Listen to switch button
|
||||||
@ -24,7 +24,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DigitalIoPin *b;
|
DigitalIoPin *b;
|
||||||
Timer *t;
|
|
||||||
StateHandler *h;
|
StateHandler *h;
|
||||||
bool b_pressed;
|
bool b_pressed;
|
||||||
int b_mode;
|
int b_mode;
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
static volatile std::atomic_int timer;
|
static volatile std::atomic_int timer;
|
||||||
static volatile std::atomic_int systicks;
|
static volatile std::atomic<uint32_t> systicks;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@ -34,6 +34,8 @@ public:
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Timer (uint32_t freq = 1000);
|
Timer (uint32_t freq = 1000);
|
||||||
|
|
||||||
|
Timer (bool mode);
|
||||||
virtual ~Timer ();
|
virtual ~Timer ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,6 +77,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
volatile std::atomic_int counter;
|
volatile std::atomic_int counter;
|
||||||
uint32_t freq;
|
uint32_t freq;
|
||||||
|
bool mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TIMER_H_ */
|
#endif /* TIMER_H_ */
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
*
|
*
|
||||||
* Created on: 21.2.2016
|
* Created on: 21.2.2016
|
||||||
* Author: krl
|
* Author: krl
|
||||||
* Based on example provided by NXP Semiconductors. See copyright notice below.
|
* Based on example provided by NXP Semiconductors. See copyright notice
|
||||||
|
* below.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -21,74 +22,81 @@
|
|||||||
* all warranties, express or implied, including all implied warranties of
|
* all warranties, express or implied, including all implied warranties of
|
||||||
* merchantability, fitness for a particular purpose and non-infringement of
|
* merchantability, fitness for a particular purpose and non-infringement of
|
||||||
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
* intellectual property rights. NXP Semiconductors assumes no responsibility
|
||||||
* or liability for the use of the software, conveys no license or rights under any
|
* or liability for the use of the software, conveys no license or rights under
|
||||||
* patent, copyright, mask work right, or any other intellectual property rights in
|
* any patent, copyright, mask work right, or any other intellectual property
|
||||||
* or to any products. NXP Semiconductors reserves the right to make changes
|
* rights in or to any products. NXP Semiconductors reserves the right to make
|
||||||
* in the software without notification. NXP Semiconductors also makes no
|
* changes in the software without notification. NXP Semiconductors also makes
|
||||||
* representation or warranty that such application will be suitable for the
|
* no representation or warranty that such application will be suitable for the
|
||||||
* specified use without further testing or modification.
|
* specified use without further testing or modification.
|
||||||
*
|
*
|
||||||
* @par
|
* @par
|
||||||
* Permission to use, copy, modify, and distribute this software and its
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* documentation is hereby granted, under NXP Semiconductors' and its
|
* documentation is hereby granted, under NXP Semiconductors' and its
|
||||||
* licensor's relevant copyrights in the software, without fee, provided that it
|
* licensor's relevant copyrights in the software, without fee, provided that
|
||||||
* is used in conjunction with NXP Semiconductors microcontrollers. This
|
* it is used in conjunction with NXP Semiconductors microcontrollers. This
|
||||||
* copyright, permission, and disclaimer notice must appear in all copies of
|
* copyright, permission, and disclaimer notice must appear in all copies of
|
||||||
* this code.
|
* this code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "I2C.h"
|
#include "I2C.h"
|
||||||
|
|
||||||
|
I2C::I2C (const I2C_config &cfg) : device (nullptr)
|
||||||
I2C::I2C(const I2C_config &cfg): device(nullptr) {
|
{
|
||||||
if(cfg.device_number == 0) {
|
// if(cfg.device_number == 0) {
|
||||||
device = LPC_I2C0;
|
device = LPC_I2C0;
|
||||||
// board init must have been called before the pins can be configured
|
// board init must have been called before the pins can be configured
|
||||||
Chip_IOCON_PinMuxSet (LPC_IOCON, 0, 22, IOCON_DIGMODE_EN | cfg.i2c_mode);
|
Chip_IOCON_PinMuxSet (LPC_IOCON, 0, 22, IOCON_DIGMODE_EN | cfg.i2c_mode);
|
||||||
Chip_IOCON_PinMuxSet (LPC_IOCON, 0, 23, IOCON_DIGMODE_EN | cfg.i2c_mode);
|
Chip_IOCON_PinMuxSet (LPC_IOCON, 0, 23, IOCON_DIGMODE_EN | cfg.i2c_mode);
|
||||||
Chip_SWM_EnableFixedPin (SWM_FIXED_I2C0_SCL);
|
Chip_SWM_EnableFixedPin (SWM_FIXED_I2C0_SCL);
|
||||||
Chip_SWM_EnableFixedPin (SWM_FIXED_I2C0_SDA);
|
Chip_SWM_EnableFixedPin (SWM_FIXED_I2C0_SDA);
|
||||||
}
|
//}
|
||||||
else {
|
// else {
|
||||||
// currently we support only I2C number 0
|
// currently we support only I2C number 0
|
||||||
}
|
//}
|
||||||
|
|
||||||
if(device) {
|
if (LPC_I2C0)
|
||||||
|
{
|
||||||
/* Enable I2C clock and reset I2C peripheral - the boot ROM does not
|
/* Enable I2C clock and reset I2C peripheral - the boot ROM does not
|
||||||
do this */
|
do this */
|
||||||
Chip_I2C_Init(device);
|
Chip_I2C_Init (LPC_I2C0);
|
||||||
|
|
||||||
/* Setup clock rate for I2C */
|
/* Setup clock rate for I2C */
|
||||||
Chip_I2C_SetClockDiv(device, cfg.clock_divider);
|
Chip_I2C_SetClockDiv (LPC_I2C0, cfg.clock_divider);
|
||||||
|
|
||||||
/* Setup I2CM transfer rate */
|
/* Setup I2CM transfer rate */
|
||||||
Chip_I2CM_SetBusSpeed(device, cfg.speed);
|
Chip_I2CM_SetBusSpeed (LPC_I2C0, cfg.speed);
|
||||||
|
|
||||||
/* Enable Master Mode */
|
/* Enable Master Mode */
|
||||||
Chip_I2CM_Enable(device);
|
Chip_I2CM_Enable (LPC_I2C0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
I2C::~I2C() {
|
I2C::~I2C ()
|
||||||
|
{
|
||||||
// TODO Auto-generated destructor stub
|
// TODO Auto-generated destructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2C::write(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize)
|
bool
|
||||||
|
I2C::write (uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize)
|
||||||
{
|
{
|
||||||
return transaction (devAddr, txBuffPtr, txSize, nullptr, 0);
|
return transaction (devAddr, txBuffPtr, txSize, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2C::read(uint8_t devAddr, uint8_t *rxBuffPtr, uint16_t rxSize)
|
bool
|
||||||
|
I2C::read (uint8_t devAddr, uint8_t *rxBuffPtr, uint16_t rxSize)
|
||||||
{
|
{
|
||||||
return transaction (devAddr, nullptr, 0, rxBuffPtr, rxSize);
|
return transaction (devAddr, nullptr, 0, rxBuffPtr, rxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
bool I2C::transaction(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize, uint8_t *rxBuffPtr, uint16_t rxSize) {
|
I2C::transaction (uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize,
|
||||||
|
uint8_t *rxBuffPtr, uint16_t rxSize)
|
||||||
|
{
|
||||||
I2CM_XFER_T i2cmXferRec;
|
I2CM_XFER_T i2cmXferRec;
|
||||||
|
|
||||||
// make sure that master is idle
|
// make sure that master is idle
|
||||||
while(!Chip_I2CM_IsMasterPending(device));
|
while (!Chip_I2CM_IsMasterPending (LPC_I2C0))
|
||||||
|
;
|
||||||
|
|
||||||
/* Setup I2C transfer record */
|
/* Setup I2C transfer record */
|
||||||
i2cmXferRec.slaveAddr = devAddr;
|
i2cmXferRec.slaveAddr = devAddr;
|
||||||
@ -98,24 +106,29 @@ bool I2C::transaction(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize, uint
|
|||||||
i2cmXferRec.txBuff = txBuffPtr;
|
i2cmXferRec.txBuff = txBuffPtr;
|
||||||
i2cmXferRec.rxBuff = rxBuffPtr;
|
i2cmXferRec.rxBuff = rxBuffPtr;
|
||||||
|
|
||||||
I2CM_XferBlocking(device, &i2cmXferRec);
|
I2CM_XferBlocking (LPC_I2C0, &i2cmXferRec);
|
||||||
// Chip_I2CM_XferBlocking returns before stop condition is fully completed
|
// Chip_I2CM_XferBlocking returns before stop condition is fully completed
|
||||||
// therefore we need to wait for master to be idle when doing back-to-back transactions (see beginning of the function)
|
// therefore we need to wait for master to be idle when doing back-to-back
|
||||||
|
// transactions (see beginning of the function)
|
||||||
|
|
||||||
/* Test for valid operation */
|
/* Test for valid operation */
|
||||||
if (i2cmXferRec.status == I2CM_STATUS_OK) {
|
if (i2cmXferRec.status == I2CM_STATUS_OK)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transmit and Receive data in master mode */
|
/* Transmit and Receive data in master mode */
|
||||||
/* This duplicates (and combines) the functionality of Chip_I2CM_Xfer and Chip_I2CM_XferBlocking with a modification
|
/* This duplicates (and combines) the functionality of Chip_I2CM_Xfer and
|
||||||
* that allows us to do a zero length write (needed to use honeywell humidity/temp sensor)
|
* Chip_I2CM_XferBlocking with a modification that allows us to do a zero
|
||||||
|
* length write (needed to use honeywell humidity/temp sensor)
|
||||||
*/
|
*/
|
||||||
uint32_t I2C::I2CM_XferBlocking(LPC_I2C_T *pI2C, I2CM_XFER_T *xfer)
|
uint32_t
|
||||||
|
I2C::I2CM_XferBlocking (LPC_I2C_T *pI2C, I2CM_XFER_T *xfer)
|
||||||
{
|
{
|
||||||
uint32_t ret = 0;
|
uint32_t ret = 0;
|
||||||
/* start transfer */
|
/* start transfer */
|
||||||
@ -125,19 +138,23 @@ uint32_t I2C::I2CM_XferBlocking(LPC_I2C_T *pI2C, I2CM_XFER_T *xfer)
|
|||||||
/* Clear controller state. */
|
/* Clear controller state. */
|
||||||
Chip_I2CM_ClearStatus (pI2C, I2C_STAT_MSTRARBLOSS | I2C_STAT_MSTSTSTPERR);
|
Chip_I2CM_ClearStatus (pI2C, I2C_STAT_MSTRARBLOSS | I2C_STAT_MSTSTSTPERR);
|
||||||
/* Write Address and RW bit to data register */
|
/* Write Address and RW bit to data register */
|
||||||
//Chip_I2CM_WriteByte(pI2C, (xfer->slaveAddr << 1) | (xfer->txSz == 0)); // original NXP version
|
// Chip_I2CM_WriteByte(pI2C, (xfer->slaveAddr << 1) | (xfer->txSz == 0)); //
|
||||||
// krl : both read and write lenght is 0 --> write (for honeywell temp sensor)
|
// original NXP version
|
||||||
Chip_I2CM_WriteByte(pI2C, (xfer->slaveAddr << 1) | (xfer->txSz == 0 && xfer->rxSz != 0));
|
// krl : both read and write lenght is 0 --> write (for honeywell temp
|
||||||
|
// sensor)
|
||||||
|
Chip_I2CM_WriteByte (pI2C, (xfer->slaveAddr << 1)
|
||||||
|
| (xfer->txSz == 0 && xfer->rxSz != 0));
|
||||||
/* Enter to Master Transmitter mode */
|
/* Enter to Master Transmitter mode */
|
||||||
Chip_I2CM_SendStart (pI2C);
|
Chip_I2CM_SendStart (pI2C);
|
||||||
|
|
||||||
while (ret == 0) {
|
while (ret == 0)
|
||||||
|
{
|
||||||
/* wait for status change interrupt */
|
/* wait for status change interrupt */
|
||||||
while (!Chip_I2CM_IsMasterPending(pI2C)) {}
|
while (!Chip_I2CM_IsMasterPending (pI2C))
|
||||||
|
{
|
||||||
|
}
|
||||||
/* call state change handler */
|
/* call state change handler */
|
||||||
ret = Chip_I2CM_XferHandler (pI2C, xfer);
|
ret = Chip_I2CM_XferHandler (pI2C, xfer);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ static uint8_t crc8(uint8_t *data, size_t size) {
|
|||||||
PressureWrapper::PressureWrapper ()
|
PressureWrapper::PressureWrapper ()
|
||||||
{
|
{
|
||||||
NVIC_DisableIRQ(I2C0_IRQn);
|
NVIC_DisableIRQ(I2C0_IRQn);
|
||||||
I2C_config config;
|
I2C_config config(0, 55000, 1309);
|
||||||
I2C i2c_c(config);
|
I2C i2c_c(config);
|
||||||
i2c = &i2c_c;
|
i2c = &i2c_c;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StateHandler/StateHandler.h"
|
#include "StateHandler/StateHandler.h"
|
||||||
#define PID 0
|
#define PID 1
|
||||||
|
|
||||||
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01,
|
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01,
|
||||||
PressureWrapper *pressure, Timer *global)
|
PressureWrapper *pressure, Timer *global)
|
||||||
@ -81,7 +81,7 @@ StateHandler::stateInit (const Event &event)
|
|||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case Event::eEnter:
|
case Event::eEnter:
|
||||||
SetState (&StateHandler::stateSensors);
|
//SetState (&StateHandler::stateSensors);
|
||||||
break;
|
break;
|
||||||
case Event::eExit:
|
case Event::eExit:
|
||||||
_lcd->clear ();
|
_lcd->clear ();
|
||||||
@ -219,13 +219,6 @@ StateHandler::handleControlButtons (uint8_t button)
|
|||||||
void
|
void
|
||||||
StateHandler::save (int eventValue, size_t mode)
|
StateHandler::save (int eventValue, size_t mode)
|
||||||
{
|
{
|
||||||
/* if pressure is not provided from main it checks it in following if{}*/
|
|
||||||
if (!eventValue)
|
|
||||||
{
|
|
||||||
/* Small delay for modbus communications with pressure sensor */
|
|
||||||
state_timer->tickCounter (1);
|
|
||||||
eventValue = pressure->getPressure ();
|
|
||||||
}
|
|
||||||
int counterValue = value[mode].getCurrent ();
|
int counterValue = value[mode].getCurrent ();
|
||||||
if (saved_curr_value[mode] != eventValue
|
if (saved_curr_value[mode] != eventValue
|
||||||
|| saved_set_value[mode] != counterValue)
|
|| saved_set_value[mode] != counterValue)
|
||||||
|
|||||||
@ -5,13 +5,12 @@
|
|||||||
* Author: tylen
|
* Author: tylen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <SwitchController.h>
|
#include "SwitchController.h"
|
||||||
|
|
||||||
SwitchController::SwitchController (DigitalIoPin *button, Timer *timer,
|
SwitchController::SwitchController (DigitalIoPin *button,
|
||||||
StateHandler *handler, int button_mode)
|
StateHandler *handler, int button_mode)
|
||||||
{
|
{
|
||||||
b = button;
|
b = button;
|
||||||
t = timer;
|
|
||||||
h = handler;
|
h = handler;
|
||||||
b_pressed = false;
|
b_pressed = false;
|
||||||
b_mode = button_mode;
|
b_mode = button_mode;
|
||||||
@ -25,51 +24,17 @@ SwitchController::~SwitchController ()
|
|||||||
void
|
void
|
||||||
SwitchController::listen ()
|
SwitchController::listen ()
|
||||||
{
|
{
|
||||||
int timer = t->getCounter ();
|
|
||||||
/** Button is pressed for the first time*/
|
/** Button is pressed for the first time*/
|
||||||
if (b->read () && !b_pressed)
|
if (b->read () && !b_pressed)
|
||||||
{
|
{
|
||||||
t->resetCounter ();
|
|
||||||
b_pressed = true;
|
b_pressed = true;
|
||||||
}
|
}
|
||||||
/** Button is released before 2 seconds*/
|
/** Button is released before 2 seconds*/
|
||||||
if (!b->read () && b_pressed && timer < 2000)
|
if (!b->read () && b_pressed)
|
||||||
{
|
{
|
||||||
h->HandleState (Event (Event::eKey, b_mode));
|
h->HandleState (Event (Event::eKey, b_mode));
|
||||||
b_pressed = false;
|
b_pressed = false;
|
||||||
t->resetCounter ();
|
|
||||||
}
|
|
||||||
/** Button is pressed after 2 seconds*/
|
|
||||||
if (b->read () && b_pressed && timer >= 2000)
|
|
||||||
{
|
|
||||||
buttonOnHold ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SwitchController::buttonOnHold ()
|
|
||||||
{
|
|
||||||
t->resetCounter ();
|
|
||||||
while (b->read ())
|
|
||||||
{
|
|
||||||
buttonInLoop ();
|
|
||||||
}
|
|
||||||
if (b_mode == BUTTON_CONTROL_TOG_MODE)
|
|
||||||
{
|
|
||||||
h->HandleState (Event (Event::eKey, b_mode));
|
|
||||||
}
|
|
||||||
b_pressed = false;
|
|
||||||
t->resetCounter ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SwitchController::buttonInLoop ()
|
|
||||||
{
|
|
||||||
if (t->getCounter () > 50 && b_mode != BUTTON_CONTROL_TOG_MODE)
|
|
||||||
{
|
|
||||||
h->HandleState (Event (Event::eKey, b_mode));
|
|
||||||
h->HandleState (Event (Event::eTick));
|
|
||||||
t->resetCounter ();
|
|
||||||
}
|
|
||||||
t->tickCounter (2);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -20,12 +20,21 @@ extern "C"
|
|||||||
|
|
||||||
Timer::Timer (uint32_t freq) : freq (freq)
|
Timer::Timer (uint32_t freq) : freq (freq)
|
||||||
{
|
{
|
||||||
|
mode = true;
|
||||||
Chip_Clock_SetSysTickClockDiv (1);
|
Chip_Clock_SetSysTickClockDiv (1);
|
||||||
uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate ();
|
uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate ();
|
||||||
SysTick_Config (sysTickRate / freq);
|
SysTick_Config (sysTickRate / freq);
|
||||||
counter = 0;
|
resetCounter();
|
||||||
timer = 0;
|
timer = 0;
|
||||||
systicks = 0;
|
systicks.store (0, std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer::Timer(bool mode)
|
||||||
|
{
|
||||||
|
this->mode = false;
|
||||||
|
resetCounter();
|
||||||
|
timer = 0;
|
||||||
|
systicks.store (0, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer::~Timer ()
|
Timer::~Timer ()
|
||||||
@ -69,5 +78,5 @@ Timer::resetCounter ()
|
|||||||
uint32_t
|
uint32_t
|
||||||
millis ()
|
millis ()
|
||||||
{
|
{
|
||||||
return systicks;
|
return systicks.load(std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,7 @@ main (void)
|
|||||||
/** Lcd & stateHandler */
|
/** Lcd & stateHandler */
|
||||||
Chip_RIT_Init (LPC_RITIMER);
|
Chip_RIT_Init (LPC_RITIMER);
|
||||||
Timer glob_time;
|
Timer glob_time;
|
||||||
|
Timer switch_time(false);
|
||||||
DigitalIoPin rs (0, 29, false, true, false);
|
DigitalIoPin rs (0, 29, false, true, false);
|
||||||
DigitalIoPin en (0, 9, false, true, false);
|
DigitalIoPin en (0, 9, false, true, false);
|
||||||
DigitalIoPin d4 (0, 10, false, true, false);
|
DigitalIoPin d4 (0, 10, false, true, false);
|
||||||
@ -56,7 +57,7 @@ main (void)
|
|||||||
LiquidCrystal lcd (&rs, &en, &d4, &d5, &d6, &d7);
|
LiquidCrystal lcd (&rs, &en, &d4, &d5, &d6, &d7);
|
||||||
//
|
//
|
||||||
lcd.setCursor (0, 0);
|
lcd.setCursor (0, 0);
|
||||||
lcd.print ("Test");
|
lcd.print ("Vent-Machine");
|
||||||
|
|
||||||
/* FAN object */
|
/* FAN object */
|
||||||
ModbusMaster fan (1);
|
ModbusMaster fan (1);
|
||||||
@ -65,38 +66,32 @@ main (void)
|
|||||||
// ModbusRegister DI1(&fan, 4, false);
|
// ModbusRegister DI1(&fan, 4, false);
|
||||||
|
|
||||||
PressureWrapper sens;
|
PressureWrapper sens;
|
||||||
|
glob_time.Sleep(1000);
|
||||||
|
|
||||||
StateHandler ventMachine (&lcd, &A01, &sens, &glob_time);
|
StateHandler ventMachine (&lcd, &A01, &sens, &glob_time);
|
||||||
/** Common pins */
|
/** Common pins */
|
||||||
DigitalIoPin b_up (0, 7, true, true, true); // A5
|
DigitalIoPin b_up (0, 7, true, true, true); // A5
|
||||||
SwitchController sw_up (&b_up, &glob_time, &ventMachine, BUTTON_CONTROL_UP);
|
SwitchController sw_up (&b_up, &ventMachine, BUTTON_CONTROL_UP);
|
||||||
|
|
||||||
DigitalIoPin b_down (0, 6, true, true, true); // A4
|
DigitalIoPin b_down (0, 6, true, true, true); // A4
|
||||||
SwitchController sw_down (&b_down, &glob_time, &ventMachine,
|
SwitchController sw_down (&b_down, &ventMachine,
|
||||||
BUTTON_CONTROL_DOWN);
|
BUTTON_CONTROL_DOWN);
|
||||||
|
|
||||||
DigitalIoPin b_toggle (0, 5, true, true, true); // A3
|
DigitalIoPin b_toggle (0, 5, true, true, true); // A3
|
||||||
SwitchController sw_toggle (&b_toggle, &glob_time, &ventMachine,
|
SwitchController sw_toggle (&b_toggle, &ventMachine,
|
||||||
BUTTON_CONTROL_TOG_MODE);
|
BUTTON_CONTROL_TOG_MODE);
|
||||||
|
|
||||||
int pressure = 0, pressure_time = 0;
|
int pressure = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
sw_up.listen ();
|
sw_up.listen ();
|
||||||
sw_down.listen ();
|
sw_down.listen ();
|
||||||
sw_toggle.listen ();
|
sw_toggle.listen ();
|
||||||
/**
|
if(glob_time.getCounter() > 3) {
|
||||||
* TODO:
|
|
||||||
* - Update current pressure to eTick
|
|
||||||
*/
|
|
||||||
#if 0
|
|
||||||
if(pressure_time == 5) {
|
|
||||||
pressure = sens.getPressure();
|
pressure = sens.getPressure();
|
||||||
pressure_time = 0;
|
glob_time.resetCounter();
|
||||||
}
|
}
|
||||||
++pressure_time;
|
|
||||||
#endif
|
|
||||||
ventMachine.HandleState (Event (Event::eTick, pressure));
|
ventMachine.HandleState (Event (Event::eTick, pressure));
|
||||||
glob_time.tickCounter (1);
|
glob_time.tickCounter (1);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user