--some updates

This commit is contained in:
Mysteo
2023-07-14 19:21:22 +03:00
parent 5c26bb8dff
commit 5f7dcde4af
21 changed files with 22075 additions and 406 deletions

View File

@@ -0,0 +1,83 @@
//===================================================================
// File: circular_buffer.cpp
//
// Desc: A Circular Buffer implementation in C++.
//
// Copyright © 2019 Edwin Cloud. All rights reserved.
//
//===================================================================
//-------------------------------------------------------------------
// Includes
//-------------------------------------------------------------------
#include <memory>
#include <stdexcept>
//-------------------------------------------------------------------
// Circular_Buffer (Class)
// We will implement the buffer with a templated class so
// the buffer can be a buffer of specified type.
//-------------------------------------------------------------------
template <typename T> class Circular_Buffer {
private:
//---------------------------------------------------------------
// Circular_Buffer - Private Member Variables
//---------------------------------------------------------------
std::unique_ptr<T[]> buffer; // using a smart pointer is safer (and we don't
// have to implement a destructor)
size_t head = 0; // size_t is an unsigned long
size_t tail = 0;
size_t max_size;
T empty_item; // we will use this to clear data
public:
//---------------------------------------------------------------
// Circular_Buffer - Public Methods
//---------------------------------------------------------------
// Create a new Circular_Buffer.
Circular_Buffer<T>(size_t max_size)
: buffer(std::unique_ptr<T[]>(new T[max_size])), max_size(max_size){};
// Add an item to this circular buffer.
void enqueue(T item) {
// insert item at back of buffer
buffer[tail] = item;
// increment tail
tail = (tail + 1) % max_size;
}
// Remove an item from this circular buffer and return it.
T dequeue() {
T item = buffer[head];
// set item at head to be empty
T empty;
buffer[head] = empty_item;
// move head foward
head = (head + 1) % max_size;
// return item
return item;
}
// Return the item at the front of this circular buffer.
T front() { return buffer[head]; }
// Return true if this circular buffer is empty, and false otherwise.
bool is_empty() { return head == tail; }
// Return true if this circular buffer is full, and false otherwise.
bool is_full() { return tail == (head - 1) % max_size; }
// Return the size of this circular buffer.
size_t size() {
if (tail >= head)
return tail - head;
return max_size - head - tail;
}
};

View File

@@ -58,7 +58,13 @@ void Error_Handler(void);
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
void MX_USART2_UART_Init(void);
#define LIGHTING_EN_Pin GPIO_PIN_4
#define LIGHTING_EN_GPIO_Port GPIOA
#define READER_EN_Pin GPIO_PIN_5
#define READER_EN_GPIO_Port GPIOA
#define ZUMMER_PINOUT_Pin GPIO_PIN_5
#define ZUMMER_PINOUT_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
@@ -68,5 +74,3 @@ void MX_USART2_UART_Init(void);
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -1,3 +1,4 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32g0xx_hal_conf.h
@@ -6,16 +7,16 @@
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
* Copyright (c) 2018 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32G0xx_HAL_CONF_H
@@ -42,7 +43,7 @@ extern "C" {
/* #define HAL_EXTI_MODULE_ENABLED */
/* #define HAL_FDCAN_MODULE_ENABLED */
/* #define HAL_HCD_MODULE_ENABLED */
/* #define HAL_I2C_MODULE_ENABLED */
#define HAL_I2C_MODULE_ENABLED
/* #define HAL_I2S_MODULE_ENABLED */
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
@@ -53,7 +54,7 @@ extern "C" {
/* #define HAL_SMARTCARD_MODULE_ENABLED */
/* #define HAL_SMBUS_MODULE_ENABLED */
/* #define HAL_SPI_MODULE_ENABLED */
/* #define HAL_TIM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_WWDG_MODULE_ENABLED */
@@ -153,7 +154,7 @@ in voltage and temperature.*/
* frequency.
*/
#if !defined (EXTERNAL_I2S1_CLOCK_VALUE)
#define EXTERNAL_I2S1_CLOCK_VALUE (12288000UL) /*!< Value of the I2S1 External clock source in Hz*/
#define EXTERNAL_I2S1_CLOCK_VALUE (48000UL) /*!< Value of the I2S1 External clock source in Hz*/
#endif /* EXTERNAL_I2S1_CLOCK_VALUE */
#if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
@@ -175,7 +176,7 @@ in voltage and temperature.*/
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority */
#define TICK_INT_PRIORITY 3U /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define INSTRUCTION_CACHE_ENABLE 1U
@@ -348,5 +349,3 @@ void assert_failed(uint8_t *file, uint32_t line);
#endif
#endif /* STM32G0xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -52,6 +52,8 @@ void HardFault_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
@@ -61,5 +63,3 @@ void SysTick_Handler(void);
#endif
#endif /* __STM32G0xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

39
Core/Inc/uart_bridge.hpp Normal file
View File

@@ -0,0 +1,39 @@
//
// Created by Mysteo on 14.07.2023.
//
#ifndef READER_MAIN_PROG_UART_BRIDGE_HPP
#define READER_MAIN_PROG_UART_BRIDGE_HPP
#include "circular_buffer.hpp"
#include "usart.h"
class UartBridge{
public:
UartBridge(bool isOn, USART_TypeDef *uart1, USART_TypeDef *uart2, uint16_t baudRate1,
uint16_t baudRate2);
Circular_Buffer<uint8_t> *uart1Buf;
Circular_Buffer<uint8_t> *uart2Buf;
bool isTurnOn() const;
void setIsTurnOn(bool isTurnOn);
static volatile uint8_t dataFromUart1;
static volatile uint8_t dataFromUart2;
void init(void);
private:
protected:
void uartInit(UART_HandleTypeDef* huart);
bool turnOn;
static UART_HandleTypeDef uart1Handle, uart2Handle;
public:
UART_HandleTypeDef* getHuart1() ;
UART_HandleTypeDef* getHuart2() ;
protected:
USART_TypeDef *uart1, *uart2;
};
#endif //READER_MAIN_PROG_UART_BRIDGE_HPP