diff --git a/PressureWrapper/.cproject b/PressureWrapper/.cproject
deleted file mode 100644
index 3270851..0000000
--- a/PressureWrapper/.cproject
+++ /dev/null
@@ -1,256 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <?xml version="1.0" encoding="UTF-8"?>
-<TargetConfig>
-<Properties property_2="LPC15xx_256K.cfx" property_3="NXP" property_4="LPC1549" property_count="5" version="100300"/>
-<infoList vendor="NXP">
-<info chip="LPC1549" connectscript="LPC15RunBootRomConnect.scp" flash_driver="LPC15xx_256K.cfx" match_id="0x0" name="LPC1549" resetscript="LPC15RunBootRomReset.scp" stub="crt_emu_cm3_gen">
-<chip>
-<name>LPC1549</name>
-<family>LPC15xx</family>
-<vendor>NXP (formerly Philips)</vendor>
-<reset board="None" core="Real" sys="Real"/>
-<clock changeable="TRUE" freq="12MHz" is_accurate="TRUE"/>
-<memory can_program="true" id="Flash" is_ro="true" type="Flash"/>
-<memory id="RAM" type="RAM"/>
-<memory id="Periph" is_volatile="true" type="Peripheral"/>
-<memoryInstance derived_from="Flash" id="MFlash256" location="0x0" size="0x40000"/>
-<memoryInstance derived_from="RAM" id="Ram0_16" location="0x2000000" size="0x4000"/>
-<memoryInstance derived_from="RAM" id="Ram1_16" location="0x2004000" size="0x4000"/>
-<memoryInstance derived_from="RAM" id="Ram2_4" location="0x2008000" size="0x1000"/>
-</chip>
-<processor>
-<name gcc_name="cortex-m3">Cortex-M3</name>
-<family>Cortex-M</family>
-</processor>
-</info>
-</infoList>
-</TargetConfig>
-
-
- LPCXpresso1549
-
-
-
-
\ No newline at end of file
diff --git a/PressureWrapper/.project b/PressureWrapper/.project
deleted file mode 100644
index 4688e60..0000000
--- a/PressureWrapper/.project
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
- PressureWrapper
-
-
- lpc_chip_15xx
- DigitalIoPin
- I2C
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.core.ccnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
-
-
diff --git a/PressureWrapper/Debug/makefile b/PressureWrapper/Debug/makefile
deleted file mode 100644
index b3a89c6..0000000
--- a/PressureWrapper/Debug/makefile
+++ /dev/null
@@ -1,77 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
--include ../makefile.init
-
-RM := rm -rf
-
-# All of the sources participating in the build are defined here
--include sources.mk
--include src/subdir.mk
--include objects.mk
-
-ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(strip $(C++_DEPS)),)
--include $(C++_DEPS)
-endif
-ifneq ($(strip $(CC_DEPS)),)
--include $(CC_DEPS)
-endif
-ifneq ($(strip $(CPP_DEPS)),)
--include $(CPP_DEPS)
-endif
-ifneq ($(strip $(CXX_DEPS)),)
--include $(CXX_DEPS)
-endif
-ifneq ($(strip $(C_DEPS)),)
--include $(C_DEPS)
-endif
-ifneq ($(strip $(C_UPPER_DEPS)),)
--include $(C_UPPER_DEPS)
-endif
-endif
-
--include ../makefile.defs
-
-OPTIONAL_TOOL_DEPS := \
-$(wildcard ../makefile.defs) \
-$(wildcard ../makefile.init) \
-$(wildcard ../makefile.targets) \
-
-
-BUILD_ARTIFACT_NAME := PressureWrapper
-BUILD_ARTIFACT_EXTENSION := a
-BUILD_ARTIFACT_PREFIX := lib
-BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),)
-
-# Add inputs and outputs from these tool invocations to the build variables
-
-# All Target
-all:
- +@$(MAKE) --no-print-directory main-build && $(MAKE) --no-print-directory post-build
-
-# Main-build Target
-main-build: libPressureWrapper.a
-
-# Tool invocations
-libPressureWrapper.a: $(OBJS) $(USER_OBJS) makefile objects.mk $(OPTIONAL_TOOL_DEPS)
- @echo 'Building target: $@'
- @echo 'Invoking: MCU Archiver'
- arm-none-eabi-ar -r "libPressureWrapper.a" $(OBJS) $(USER_OBJS) $(LIBS)
- @echo 'Finished building target: $@'
- @echo ' '
-
-# Other Targets
-clean:
- -$(RM) libPressureWrapper.a
- -@echo ' '
-
-post-build:
- -@echo 'Performing post-build steps'
- -arm-none-eabi-size "libPressureWrapper.a" ; # arm-none-eabi-objdump -h -S "libPressureWrapper.a" >"libPressureWrapper.lss"
- -@echo ' '
-
-.PHONY: all clean dependents main-build post-build
-
--include ../makefile.targets
diff --git a/PressureWrapper/Debug/objects.mk b/PressureWrapper/Debug/objects.mk
deleted file mode 100644
index 742c2da..0000000
--- a/PressureWrapper/Debug/objects.mk
+++ /dev/null
@@ -1,8 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-USER_OBJS :=
-
-LIBS :=
-
diff --git a/PressureWrapper/Debug/sources.mk b/PressureWrapper/Debug/sources.mk
deleted file mode 100644
index ff3de3d..0000000
--- a/PressureWrapper/Debug/sources.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-ASM_SRCS :=
-C++_SRCS :=
-CC_SRCS :=
-CPP_SRCS :=
-CXX_SRCS :=
-C_SRCS :=
-C_UPPER_SRCS :=
-OBJ_SRCS :=
-O_SRCS :=
-S_SRCS :=
-S_UPPER_SRCS :=
-ARCHIVES :=
-C++_DEPS :=
-CC_DEPS :=
-CPP_DEPS :=
-CXX_DEPS :=
-C_DEPS :=
-C_UPPER_DEPS :=
-OBJS :=
-
-# Every subdirectory with source files must be described here
-SUBDIRS := \
-src \
-
diff --git a/PressureWrapper/Debug/src/PressureWrapper.su b/PressureWrapper/Debug/src/PressureWrapper.su
deleted file mode 100644
index 2659eb8..0000000
--- a/PressureWrapper/Debug/src/PressureWrapper.su
+++ /dev/null
@@ -1,3 +0,0 @@
-../src/PressureWrapper.cpp:10:1:PressureWrapper::PressureWrapper() 16 static
-../src/PressureWrapper.cpp:15:1:PressureWrapper::~PressureWrapper() 16 static
-../src/PressureWrapper.cpp:15:1:virtual PressureWrapper::~PressureWrapper() 16 static
diff --git a/PressureWrapper/Debug/src/subdir.mk b/PressureWrapper/Debug/src/subdir.mk
deleted file mode 100644
index 59024df..0000000
--- a/PressureWrapper/Debug/src/subdir.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-################################################################################
-# Automatically-generated file. Do not edit!
-################################################################################
-
-# Add inputs and outputs from these tool invocations to the build variables
-CPP_SRCS += \
-../src/PressureWrapper.cpp
-
-CPP_DEPS += \
-./src/PressureWrapper.d
-
-OBJS += \
-./src/PressureWrapper.o
-
-
-# Each subdirectory must supply rules for building sources it contributes
-src/%.o: ../src/%.cpp src/subdir.mk
- @echo 'Building file: $<'
- @echo 'Invoking: MCU C++ Compiler'
- arm-none-eabi-c++ -DDEBUG -D__CODE_RED -D__NEWLIB__ -DCORE_M3 -D__USE_LPCOPEN -D__LPC15XX__ -I"/Users/evgenymeshcheryakov/Documents/Metropolia/3rd/Embedded Systems Programming TX00CI61-3011/ESP-Ventilation/PressureWrapper/inc" -I"/Users/evgenymeshcheryakov/Documents/Metropolia/3rd/Embedded Systems Programming TX00CI61-3011/ESP-Ventilation/lpc_board_nxp_lpcxpresso_1549/inc" -I"/Users/evgenymeshcheryakov/Documents/Metropolia/3rd/Embedded Systems Programming TX00CI61-3011/ESP-Ventilation/lpc_chip_15xx/inc" -I"/Users/evgenymeshcheryakov/Documents/Metropolia/3rd/Embedded Systems Programming TX00CI61-3011/ESP-Ventilation/DigitalIoPin/inc" -I"/Users/evgenymeshcheryakov/Documents/Metropolia/3rd/Embedded Systems Programming TX00CI61-3011/ESP-Ventilation/I2C/inc" -O0 -fno-common -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fmerge-constants -fmacro-prefix-map="$(
-
-
-
- ${MacroStart}workspace_loc:/${ProjName}/inc${MacroEnd}
-
-
- ${MacroStart}workspace_loc:/${ProjName}/inc${MacroEnd}
-
-
- ${ProjName}
-
-
- ${MacroStart}workspace_loc:/${ProjName}/Debug${MacroEnd}
-
-
- ${MacroStart}workspace_loc:/${ProjName}/Release${MacroEnd}
-
-
- ${ProjName}
-
-
-
diff --git a/PressureWrapper/src/PressureWrapper.cpp b/PressureWrapper/src/PressureWrapper.cpp
deleted file mode 100644
index 5f92992..0000000
--- a/PressureWrapper/src/PressureWrapper.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * PressureWrapper.cpp
- *
- * Created on: 5 Oct 2022
- * Author: evgenymeshcheryakov
- */
-
-#include
-
-PressureWrapper::PressureWrapper (I2C *i2c) : i2c(i2c)
-{
-
-}
-
-PressureWrapper::~PressureWrapper ()
-{
- // TODO Auto-generated destructor stub
-}
-
-bool PressureWrapper::getStatus() {
- uint8_t control_register = 0x01;
- uint8_t status = 0;
- i2c->transaction(ADDRESS, &control_register, 1, &status, 1);
-}
-
-PRESSURE_DATA* PressureWrapper::getPressure () {
- uint8_t getMeasurementComm = 0xF1;
- i2c->transaction(ADDRESS, &getMeasurementComm, 1, data.rBuffer, 3);
- //i2c->transaction(ADDRESS, &getMeasurementComm, 1, data.crc, 1);
- return &data;
-}
diff --git a/esp-vent-main/src/I2C.cpp b/esp-vent-main/src/I2C.cpp
new file mode 100644
index 0000000..8536719
--- /dev/null
+++ b/esp-vent-main/src/I2C.cpp
@@ -0,0 +1,143 @@
+/*
+ * I2C.cpp
+ *
+ * Created on: 21.2.2016
+ * Author: krl
+ * Based on example provided by NXP Semiconductors. See copyright notice below.
+ */
+
+/*
+ * @brief I2CM bus master example using polling mode
+ *
+ * @note
+ * Copyright(C) NXP Semiconductors, 2014
+ * All rights reserved.
+ *
+ * @par
+ * Software that is described herein is for illustrative purposes only
+ * which provides customers with programming information regarding the
+ * LPC products. This software is supplied "AS IS" without any warranties of
+ * any kind, and NXP Semiconductors and its licensor disclaim any and
+ * all warranties, express or implied, including all implied warranties of
+ * merchantability, fitness for a particular purpose and non-infringement of
+ * intellectual property rights. NXP Semiconductors assumes no responsibility
+ * or liability for the use of the software, conveys no license or rights under any
+ * patent, copyright, mask work right, or any other intellectual property rights in
+ * or to any products. NXP Semiconductors reserves the right to make changes
+ * in the software without notification. NXP Semiconductors also makes no
+ * representation or warranty that such application will be suitable for the
+ * specified use without further testing or modification.
+ *
+ * @par
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation is hereby granted, under NXP Semiconductors' and its
+ * licensor's relevant copyrights in the software, without fee, provided that it
+ * is used in conjunction with NXP Semiconductors microcontrollers. This
+ * copyright, permission, and disclaimer notice must appear in all copies of
+ * this code.
+ */
+
+#include "../inc/I2C.h"
+
+
+I2C::I2C(const I2C_config &cfg): device(nullptr) {
+ if(cfg.device_number == 0) {
+ device = LPC_I2C0;
+ // 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, 23, IOCON_DIGMODE_EN | cfg.i2c_mode);
+ Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SCL);
+ Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SDA);
+ }
+ else {
+ // currently we support only I2C number 0
+ }
+
+ if(device) {
+ /* Enable I2C clock and reset I2C peripheral - the boot ROM does not
+ do this */
+ Chip_I2C_Init(device);
+
+ /* Setup clock rate for I2C */
+ Chip_I2C_SetClockDiv(device, cfg.clock_divider);
+
+ /* Setup I2CM transfer rate */
+ Chip_I2CM_SetBusSpeed(device, cfg.speed);
+
+ /* Enable Master Mode */
+ Chip_I2CM_Enable(device);
+ }
+}
+
+I2C::~I2C() {
+ // TODO Auto-generated destructor stub
+}
+
+bool I2C::write(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize)
+{
+ return transaction(devAddr, txBuffPtr, txSize, nullptr, 0);
+}
+
+bool I2C::read(uint8_t devAddr, uint8_t *rxBuffPtr, uint16_t rxSize)
+{
+ return transaction(devAddr, nullptr, 0, rxBuffPtr, rxSize);
+}
+
+
+bool I2C::transaction(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize, uint8_t *rxBuffPtr, uint16_t rxSize) {
+ I2CM_XFER_T i2cmXferRec;
+
+ // make sure that master is idle
+ while(!Chip_I2CM_IsMasterPending(LPC_I2C0));
+
+ /* Setup I2C transfer record */
+ i2cmXferRec.slaveAddr = devAddr;
+ i2cmXferRec.status = 0;
+ i2cmXferRec.txSz = txSize;
+ i2cmXferRec.rxSz = rxSize;
+ i2cmXferRec.txBuff = txBuffPtr;
+ i2cmXferRec.rxBuff = rxBuffPtr;
+
+ I2CM_XferBlocking(LPC_I2C0, &i2cmXferRec);
+ // 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)
+
+ /* Test for valid operation */
+ if (i2cmXferRec.status == I2CM_STATUS_OK) {
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+/* Transmit and Receive data in master mode */
+/* This duplicates (and combines) the functionality of Chip_I2CM_Xfer and 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 ret = 0;
+ /* start transfer */
+
+ /* set the transfer status as busy */
+ xfer->status = I2CM_STATUS_BUSY;
+ /* Clear controller state. */
+ Chip_I2CM_ClearStatus(pI2C, I2C_STAT_MSTRARBLOSS | I2C_STAT_MSTSTSTPERR);
+ /* Write Address and RW bit to data register */
+ //Chip_I2CM_WriteByte(pI2C, (xfer->slaveAddr << 1) | (xfer->txSz == 0)); // original NXP version
+ // 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 */
+ Chip_I2CM_SendStart(pI2C);
+
+ while (ret == 0) {
+ /* wait for status change interrupt */
+ while (!Chip_I2CM_IsMasterPending(pI2C)) {}
+ /* call state change handler */
+ ret = Chip_I2CM_XferHandler(pI2C, xfer);
+ }
+ return ret;
+}
+
+
diff --git a/esp-vent-main/src/I2C.h b/esp-vent-main/src/I2C.h
new file mode 100644
index 0000000..d72610d
--- /dev/null
+++ b/esp-vent-main/src/I2C.h
@@ -0,0 +1,33 @@
+/*
+ * I2C.h
+ *
+ * Created on: 21.2.2016
+ * Author: krl
+ */
+
+#ifndef I2C_H_
+#define I2C_H_
+
+#include "chip.h"
+
+struct I2C_config {
+ unsigned int device_number;
+ unsigned int speed;
+ unsigned int clock_divider;
+ unsigned int i2c_mode;
+ I2C_config(): device_number(0), speed(100000), clock_divider(40), i2c_mode(IOCON_SFI2C_EN) {};
+};
+
+class I2C {
+public:
+ I2C(const I2C_config &cfg);
+ virtual ~I2C();
+ bool transaction(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize, uint8_t *rxBuffPtr, uint16_t rxSize);
+ bool write(uint8_t devAddr, uint8_t *txBuffPtr, uint16_t txSize);
+ bool read(uint8_t devAddr, uint8_t *rxBuffPtr, uint16_t rxSize);
+private:
+ LPC_I2C_T *device;
+ static uint32_t I2CM_XferBlocking(LPC_I2C_T *pI2C, I2CM_XFER_T *xfer);
+};
+
+#endif /* I2C_H_ */
diff --git a/esp-vent-main/src/PressureWrapper.cpp b/esp-vent-main/src/PressureWrapper.cpp
new file mode 100644
index 0000000..3dcf978
--- /dev/null
+++ b/esp-vent-main/src/PressureWrapper.cpp
@@ -0,0 +1,47 @@
+/*
+ * PressureWrapper.cpp
+ *
+ * Created on: 5 Oct 2022
+ * Author: evgenymeshcheryakov
+ */
+
+#include "PressureWrapper.h"
+
+static uint8_t crc8(uint8_t *data, size_t size) {
+ uint8_t crc = 0x00;
+ uint8_t byteCtr;
+ //calculates 8-Bit checksum with given polynomial
+ for (byteCtr = 0; byteCtr < size; ++byteCtr) {
+ crc ^= (data[byteCtr]);
+ for (uint8_t bit = 8; bit > 0; --bit) {
+ if (crc & 0x80) crc = (crc << 1) ^ 0x131; //P(x)=x^8+x^5+x^4+1 = 0001 0011 0001
+ else crc = (crc << 1);
+ }
+ }
+ return crc;
+}
+
+PressureWrapper::PressureWrapper ()
+{
+ NVIC_DisableIRQ(I2C0_IRQn);
+ I2C_config config;
+ I2C i2c_c(config);
+ i2c = &i2c_c;
+}
+
+PressureWrapper::~PressureWrapper ()
+{
+ // TODO Auto-generated destructor stub
+}
+
+int PressureWrapper::getPressure() {
+
+}
+
+PRESSURE_DATA* PressureWrapper::getRawPressure () {
+ uint8_t getMeasurementComm = 0xF1;
+ i2c->transaction(0x40, &getMeasurementComm, 1, data.rBuffer, 3);
+ return &data;
+}
+
+
diff --git a/PressureWrapper/inc/PressureWrapper.h b/esp-vent-main/src/PressureWrapper.h
similarity index 83%
rename from PressureWrapper/inc/PressureWrapper.h
rename to esp-vent-main/src/PressureWrapper.h
index 77c5e84..718926e 100644
--- a/PressureWrapper/inc/PressureWrapper.h
+++ b/esp-vent-main/src/PressureWrapper.h
@@ -8,7 +8,6 @@
#ifndef PRESSUREWRAPPER_H_
#define PRESSUREWRAPPER_H_
-#include "DigitalIoPin.h"
#include "I2C.h"
#define ADDRESS 0x40
@@ -23,21 +22,21 @@ typedef struct _PRESSURE{
class PressureWrapper
{
public:
- PressureWrapper (I2C *i2c);
+ PressureWrapper ();
/**
* @brief Get the Status object
*
* @return true
* @return false
*/
- bool getStatus ();
- PRESSURE_DATA* getPressure ();
+ int getPressure ();
virtual ~PressureWrapper ();
private:
I2C *i2c;
PRESSURE_DATA data = {{0, 0}, 0};
+ PRESSURE_DATA* getRawPressure ();
};
#endif /* PRESSUREWRAPPER_H_ */