Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Mar 29, 2024
1 parent a15ed79 commit 165db5a
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<listOptionValue builtIn="false" value="../Core/External/Tools/Indicator"/>
<listOptionValue builtIn="false" value="../Core/External/Scheduler"/>
<listOptionValue builtIn="false" value="../Core/External/Scheduler/State"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/RingBuffer"/>
<listOptionValue builtIn="false" value="../ThirdParty"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy"/>
Expand All @@ -78,6 +79,7 @@
<listOptionValue builtIn="false" value="../Core/External/Tools/Indicator"/>
<listOptionValue builtIn="false" value="../Core/External/Scheduler"/>
<listOptionValue builtIn="false" value="../Core/External/Scheduler/State"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/RingBuffer"/>
<listOptionValue builtIn="false" value="../ThirdParty"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy"/>
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ else ()
add_compile_options(-Og -g)
endif ()

include_directories(Core/Inc Core/External/Sensor Core/External/Proto Core/External/Proto/Generated Core/External/Proto/Buffer Core/External/Tools/Indicator Core/External/Scheduler Core/External/Scheduler/State ThirdParty Drivers/STM32L4xx_HAL_Driver/Inc Drivers/STM32L4xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32L4xx/Include Drivers/CMSIS/Include)
include_directories(Core/Inc Core/External/Sensor Core/External/Proto Core/External/Proto/Generated Core/External/Proto/Buffer Core/External/Tools/Indicator Core/External/Scheduler Core/External/Scheduler/State Core/External/Tools/RingBuffer ThirdParty Drivers/STM32L4xx_HAL_Driver/Inc Drivers/STM32L4xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32L4xx/Include Drivers/CMSIS/Include)

add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32L476xx)

Expand Down
1 change: 1 addition & 0 deletions Core/External/Proto/proto.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "proto.h"
33 changes: 31 additions & 2 deletions Core/External/Proto/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,42 @@
#include "settings.h"

/**
* Represents parser used to
* Represents parser used to decompose and composite request and response.
*/
class ProtoParser {
public:


private:
light_detector:: r;
/**
* Represents data bus request implementation.
*/
light_detector::DataBusRequest dataBusRequest;

/**
* Represents data bus response implementation.
*/
light_detector::DataBusResponse dataBusResponse;

/**
* Represents info bus request implementation.
*/
light_detector::InfoBusRequest infoBusRequest;

/**
* Represents info bus response implementation.
*/
light_detector::InfoBusResponse infoBusResponse;

/**
* Represents settings bus request implementation.
*/
light_detector::SettingsBusRequest settingsBusRequest;

/**
* Represents settings bus response implementation.
*/
light_detector::SettingsBusResponse settingsBusResponse;
};

#endif //LIGHT_DETECTOR_PROTO_H
3 changes: 0 additions & 3 deletions Core/External/Scheduler/State/state.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef LIGHT_DETECTOR_STATE_H
#define LIGHT_DETECTOR_STATE_H

#include <mutex>

/**
* Represents device state handler.
*/
Expand All @@ -11,7 +9,6 @@ class State {


private:
std::mutex mutex;
};

#endif //LIGHT_DETECTOR_STATE_H
16 changes: 9 additions & 7 deletions Core/External/Scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ void Scheduler::handle_tick() {
handle_response();
}

void Scheduler::handle_status_check() {

}

void Scheduler::handle_request() {}() {
void Scheduler::handle_request() {
if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) == SET) {
HAL_UART_Receive(&huart2, (int16_t *) &CAM_reso_W, 2, 1000);
uint8_t buffer[100];

HAL_UART_Receive(&huart2, buffer, sizeof(buffer), 1000);
}
}

void Scheduler::handle_response() {}() {
void Scheduler::handle_response() {
if (TSL2591X::is_configured()) {
TSL2591X::read_lux();

Expand All @@ -26,4 +24,8 @@ void Scheduler::handle_response() {}() {
// printf("Visible light: %d\r\n", TSL2591_ReadVisible());
// printf("Full spectrum (IR + visible) light: %d\r\n\r\n", TSL2591X_ReadFull());
}
}

void Scheduler::handle_status_check() {

}
3 changes: 1 addition & 2 deletions Core/External/Tools/Indicator/indicator.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef LIGHT_DETECTOR_INDICATOR_H
#define LIGHT_DETECTOR_INDICATOR_H

#include <mutex>
#include "state.h"
#include "gpio.h"

Expand Down Expand Up @@ -40,7 +39,7 @@ class Indicator {
*/
static void toggle_invalid_request();
private:

};

#endif //LIGHT_DETECTOR_INDICATOR_H
9 changes: 9 additions & 0 deletions Core/External/Tools/Mutex/mutex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "mutex.h"

void Mutex::lock() {

}

void Mutex::unlock() {

}
20 changes: 20 additions & 0 deletions Core/External/Tools/Mutex/mutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef LIGHT_DETECTOR_MUTEX_H
#define LIGHT_DETECTOR_MUTEX_H

/**
* Represents mutex implementation for the board.
*/
class Mutex {
public:
/**
* Attempts to perform lock operation for the mutex.
*/
static void lock();

/**
* Attempts to perform unlock operation for the mutex.
*/
static void unlock();
};

#endif //LIGHT_DETECTOR_MUTEX_H
48 changes: 48 additions & 0 deletions Core/External/Tools/RingBuffer/ring_buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "ring_buffer.h"

#include <string.h>

uint16_t RingBuffer_GetFreeSpace(RingBuffer *buf) {
if(buf->tail == buf->head)
return RING_BUFFER_LENGTH - 1;

if(buf->head > buf->tail)
return RING_BUFFER_LENGTH - ((buf->head - buf->tail) + 1);
else
return (buf->tail - buf->head) - 1;
}

uint16_t RingBuffer_GetDataLength(RingBuffer *buf) {
return RING_BUFFER_LENGTH - (RingBuffer_GetFreeSpace(buf) + 1);
}

void RingBuffer_Init(RingBuffer *buf) {
buf->head = buf->tail = 0;
memset(buf->buf, 0, RING_BUFFER_LENGTH);
}

uint16_t RingBuffer_Read(RingBuffer *buf, uint8_t *data, uint16_t len) {
uint16_t counter = 0;

while(buf->tail != buf->head && counter < len) {
data[counter++] = buf->buf[buf->tail];
buf->tail = (buf->tail + 1) % RING_BUFFER_LENGTH;
}
return counter;
}

uint8_t RingBuffer_Write(RingBuffer *buf, uint8_t *data, uint16_t len) {
uint16_t counter = 0;
uint16_t freeSpace = RingBuffer_GetFreeSpace(buf);

if(freeSpace == 0)
return RING_BUFFER_FULL;
else if (freeSpace < len)
return RING_BUFFER_NO_SUFFICIENT_SPACE;

while(counter < len) {
buf->buf[buf->head] = data[counter++];
buf->head = (buf->head + 1) % RING_BUFFER_LENGTH;
}
return RING_BUFFER_OK;
}
30 changes: 30 additions & 0 deletions Core/External/Tools/RingBuffer/ring_buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef LIGHT_DETECTOR_RING_BUFFER_H
#define LIGHT_DETECTOR_RING_BUFFER_H

#include <stdint.h>

#define RING_BUFFER_LENGTH 1000

typedef struct {
uint8_t buf[RING_BUFFER_LENGTH];
#if RING_BUFFER_LENGTH < 255
uint8_t head, tail;
#else
uint16_t head, tail;
#endif
} RingBuffer;

typedef enum {
RING_BUFFER_OK = 0x0,
RING_BUFFER_FULL,
RING_BUFFER_NO_SUFFICIENT_SPACE
} RingBuffer_Status;

uint16_t RingBuffer_GetDataLength(RingBuffer *buf);
uint16_t RingBuffer_GetFreeSpace(RingBuffer *buf);
void RingBuffer_Init(RingBuffer *buf);
uint16_t RingBuffer_Read(RingBuffer *buf, uint8_t *data, uint16_t len);
uint8_t RingBuffer_Write(RingBuffer *buf, uint8_t *data, uint16_t len);


#endif //LIGHT_DETECTOR_RING_BUFFER_H
8 changes: 6 additions & 2 deletions Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ void SystemClock_Config(void);
* @param htim - incoming timer tick data.
*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
HAL_TIM_Base_Stop_IT(&htim16);

if (htim == &htim16) {
Scheduler::handle_tick();
} else {
__NOP();
}

HAL_TIM_Base_Start_IT(&htim16);
}

/**
Expand Down Expand Up @@ -105,8 +109,6 @@ int main(void) {
MX_TIM16_Init();
/* USER CODE BEGIN 2 */

HAL_TIM_Base_Start_IT(&htim16);

/* USER CODE END 2 */

/* Infinite loop */
Expand All @@ -117,6 +119,8 @@ int main(void) {
TSL2591X::init();

Indicator::toggle_initialization_success();

HAL_TIM_Base_Start_IT(&htim16);
} else {
Indicator::toggle_initialization_failure();
}
Expand Down

0 comments on commit 165db5a

Please sign in to comment.