Merge branch 'dev' into ui
This commit is contained in:
commit
4487f854cd
@ -51,7 +51,7 @@ CFILES += stack-check.c
|
|||||||
|
|
||||||
CFILES += ui/lcd.c ui/menu.c
|
CFILES += ui/lcd.c ui/menu.c
|
||||||
|
|
||||||
CFILES += onewire-if.c onewire-temp-sensors.c
|
#CFILES += onewire-temp-sensors.c
|
||||||
|
|
||||||
DEFINES += -DDEBUGBUILD
|
DEFINES += -DDEBUGBUILD
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* This file is part of the Reflow Oven Controller Project.
|
|
||||||
*
|
|
||||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the reflow oven controller project.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ONEWIRE_IF_H__
|
|
||||||
#define __ONEWIRE_IF_H__
|
|
||||||
|
|
||||||
#include <stm-periph/uart.h>
|
|
||||||
|
|
||||||
int onewire_if_init_uart(struct stm_uart *uart, uint32_t brr_val, USART_TypeDef *onewire_uart, volatile uint32_t *rcc_reg, uint8_t rcc_bit_num);
|
|
||||||
|
|
||||||
void onewire_if_disable(struct stm_uart *uart);
|
|
||||||
|
|
||||||
int onewire_if_send_byte(struct stm_uart *uart);
|
|
||||||
|
|
||||||
int onewire_if_receive_byte(struct stm_uart *uart);
|
|
||||||
|
|
||||||
#endif /* __ONEWIRE_IF_H__ */
|
|
@ -1,47 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* This file is part of the Reflow Oven Controller Project.
|
|
||||||
*
|
|
||||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the reflow oven controller project.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifndef __ONEWIRE_TEMP_SENSORS_H__
|
|
||||||
#define __ONEWIRE_TEMP_SENSORS_H__
|
|
||||||
|
|
||||||
#define ONEWIRE_TEMP_PORT GPIOB
|
|
||||||
#define ONEWIRE_TEMP_RCC_MASK RCC_AHB1ENR_GPIOBEN
|
|
||||||
#define ONEWIRE_TEMP_TX_PIN 10U
|
|
||||||
#define ONEWIRE_TEMP_RX_PIN 11U
|
|
||||||
#define ONEWIRE_TEMP_AF_NUM 7U
|
|
||||||
|
|
||||||
#define ONEWIRE_UART_DEV USART3
|
|
||||||
|
|
||||||
void onewire_temp_sensors_setup_hw();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief onewire_temp_sensors_discover
|
|
||||||
* @param id_list
|
|
||||||
* @param list_len
|
|
||||||
* @return Negative: error, >= 0: amount of discovered sensors
|
|
||||||
*/
|
|
||||||
int onewire_temp_sensors_discover(uint32_t *id_list, size_t list_len);
|
|
||||||
|
|
||||||
float onewire_temp_sensor_read_temp(uint32_t id);
|
|
||||||
|
|
||||||
#endif /* __ONEWIRE_TEMP_SENSORS_H__ */
|
|
@ -63,5 +63,6 @@ void systick_setup(void);
|
|||||||
*/
|
*/
|
||||||
void systick_wait_ms(uint32_t ms);
|
void systick_wait_ms(uint32_t ms);
|
||||||
|
|
||||||
|
uint64_t systick_get_global_tick();
|
||||||
|
|
||||||
#endif /* __SYSTICK_H__ */
|
#endif /* __SYSTICK_H__ */
|
||||||
|
@ -96,6 +96,14 @@ int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff,
|
|||||||
*/
|
*/
|
||||||
void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff);
|
void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get fill level of peripheral to memory DMA ring buffer
|
||||||
|
* @param buff Buffer
|
||||||
|
* @param fill_level fill level to write data to
|
||||||
|
* @return 0 if success
|
||||||
|
*/
|
||||||
|
int dma_ring_buffer_periph_to_mem_fill_level(struct dma_ring_buffer_to_mem *buff, size_t *fill_level);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize ring buffer to streaming data from meory to a peripheral
|
* @brief Initialize ring buffer to streaming data from meory to a peripheral
|
||||||
* @param[in,out] dma_buffer DMA ring buffer structure
|
* @param[in,out] dma_buffer DMA ring buffer structure
|
||||||
@ -138,6 +146,14 @@ void dma_ring_buffer_mem_to_periph_int_callback(struct dma_ring_buffer_to_periph
|
|||||||
*/
|
*/
|
||||||
void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff);
|
void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get fill level of mem to periph DMA ring buffer
|
||||||
|
* @param buff Buffer
|
||||||
|
* @param fill_level fill level to write data to
|
||||||
|
* @return 0 if success
|
||||||
|
*/
|
||||||
|
int dma_ring_buffer_mem_to_periph_fill_level(struct dma_ring_buffer_to_periph *buff, size_t *fill_level);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* __DMA_RING_BUFFER_H__ */
|
#endif /* __DMA_RING_BUFFER_H__ */
|
||||||
|
@ -48,6 +48,8 @@ struct stm_uart {
|
|||||||
|
|
||||||
int uart_init(struct stm_uart *uart);
|
int uart_init(struct stm_uart *uart);
|
||||||
|
|
||||||
|
void uart_change_brr(struct stm_uart *uart, uint32_t brr);
|
||||||
|
|
||||||
void uart_disable(struct stm_uart *uart);
|
void uart_disable(struct stm_uart *uart);
|
||||||
|
|
||||||
void uart_send_char(struct stm_uart *uart, char c);
|
void uart_send_char(struct stm_uart *uart, char c);
|
||||||
@ -68,5 +70,8 @@ int uart_check_rx_avail(struct stm_uart *uart);
|
|||||||
|
|
||||||
void uart_tx_dma_complete_int_callback(struct stm_uart *uart);
|
void uart_tx_dma_complete_int_callback(struct stm_uart *uart);
|
||||||
|
|
||||||
|
size_t uart_dma_tx_queue_avail(struct stm_uart *uart);
|
||||||
|
|
||||||
|
size_t uart_dma_rx_queue_avail(struct stm_uart *uart);
|
||||||
|
|
||||||
#endif /* UART_UART_H_ */
|
#endif /* UART_UART_H_ */
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* This file is part of the Reflow Oven Controller Project.
|
|
||||||
*
|
|
||||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the reflow oven controller project.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <reflow-controller/onewire-if.h>
|
|
||||||
|
|
||||||
int onewire_if_init_uart(struct stm_uart *uart, uint32_t brr_val, USART_TypeDef *onewire_uart, volatile uint32_t *rcc_reg, uint8_t rcc_bit_num)
|
|
||||||
{
|
|
||||||
if (!uart)
|
|
||||||
return -1000;
|
|
||||||
|
|
||||||
uart->rx = 1;
|
|
||||||
uart->tx = 1;
|
|
||||||
uart->brr_val = brr_val;
|
|
||||||
uart->rcc_reg = rcc_reg;
|
|
||||||
uart->uart_dev = onewire_uart;
|
|
||||||
uart->rcc_bit_no = rcc_bit_num;
|
|
||||||
uart->dma_rx_buff = NULL;
|
|
||||||
uart->dma_tx_buff = NULL;
|
|
||||||
|
|
||||||
return uart_init(uart);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onewire_if_disable(struct stm_uart *uart)
|
|
||||||
{
|
|
||||||
if (!uart)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uart_disable(uart);
|
|
||||||
}
|
|
||||||
|
|
||||||
int onewire_if_send_byte(struct stm_uart *uart)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int onewire_if_receive_byte(struct stm_uart *uart)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
/* Reflow Oven Controller
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
||||||
*
|
|
||||||
* This file is part of the Reflow Oven Controller Project.
|
|
||||||
*
|
|
||||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with the reflow oven controller project.
|
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stm32/stm32f4xx.h>
|
|
||||||
#include <stm-periph/uart.h>
|
|
||||||
#include <reflow-controller/onewire-if.h>
|
|
||||||
#include <reflow-controller/onewire-temp-sensors.h>
|
|
||||||
#include <stm-periph/clock-enable-manager.h>
|
|
||||||
#include <stm-periph/stm32-gpio-macros.h>
|
|
||||||
|
|
||||||
static struct stm_uart if_uart;
|
|
||||||
|
|
||||||
void onewire_temp_sensors_setup_hw()
|
|
||||||
{
|
|
||||||
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ONEWIRE_TEMP_RCC_MASK));
|
|
||||||
|
|
||||||
ONEWIRE_TEMP_PORT->OTYPER |= OTYP_OPENDRAIN(ONEWIRE_TEMP_TX_PIN);
|
|
||||||
ONEWIRE_TEMP_PORT->MODER &= MODER_DELETE(ONEWIRE_TEMP_RX_PIN) & MODER_DELETE(ONEWIRE_TEMP_TX_PIN);
|
|
||||||
ONEWIRE_TEMP_PORT->MODER |= ALTFUNC(ONEWIRE_TEMP_RX_PIN) | ALTFUNC(ONEWIRE_TEMP_TX_PIN);
|
|
||||||
SETAF(ONEWIRE_TEMP_PORT, ONEWIRE_TEMP_RX_PIN, ONEWIRE_TEMP_AF_NUM);
|
|
||||||
SETAF(ONEWIRE_TEMP_PORT, ONEWIRE_TEMP_TX_PIN, ONEWIRE_TEMP_AF_NUM);
|
|
||||||
|
|
||||||
(void)onewire_if_init_uart(&if_uart, 1, ONEWIRE_UART_DEV, &RCC->APB1ENR, BITMASK_TO_BITNO(RCC_APB1ENR_USART3EN));
|
|
||||||
}
|
|
||||||
|
|
@ -33,6 +33,19 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static size_t calculate_ring_buffer_fill_level(size_t buffer_size, size_t get_idx, size_t put_idx)
|
||||||
|
{
|
||||||
|
size_t fill_level;
|
||||||
|
|
||||||
|
if (put_idx >= get_idx) {
|
||||||
|
fill_level = (put_idx - get_idx);
|
||||||
|
} else {
|
||||||
|
fill_level = buffer_size - get_idx + put_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fill_level;
|
||||||
|
}
|
||||||
|
|
||||||
static int dma_ring_buffer_switch_clock_enable(uint8_t base_dma, bool clk_en)
|
static int dma_ring_buffer_switch_clock_enable(uint8_t base_dma, bool clk_en)
|
||||||
{
|
{
|
||||||
int ret_val;
|
int ret_val;
|
||||||
@ -141,6 +154,19 @@ void dma_ring_buffer_periph_to_mem_stop(struct dma_ring_buffer_to_mem *buff)
|
|||||||
memset(buff, 0, sizeof(struct dma_ring_buffer_to_mem));
|
memset(buff, 0, sizeof(struct dma_ring_buffer_to_mem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dma_ring_buffer_periph_to_mem_fill_level(struct dma_ring_buffer_to_mem *buff, size_t *fill_level)
|
||||||
|
{
|
||||||
|
size_t put_idx;
|
||||||
|
|
||||||
|
if (!buff || !fill_level)
|
||||||
|
return -1000;
|
||||||
|
|
||||||
|
put_idx = buff->buffer_count - buff->dma->NDTR;
|
||||||
|
*fill_level = calculate_ring_buffer_fill_level(buff->buffer_count, buff->get_idx, put_idx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg)
|
int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *dma_buffer, uint8_t base_dma_id, DMA_Stream_TypeDef *dma_stream, size_t buffer_element_count, size_t element_size, volatile void *data_buffer, uint8_t dma_trigger_channel, void *dest_reg)
|
||||||
{
|
{
|
||||||
if (!dma_buffer || !dma_stream || !data_buffer || !dest_reg)
|
if (!dma_buffer || !dma_stream || !data_buffer || !dest_reg)
|
||||||
@ -163,19 +189,6 @@ int dma_ring_buffer_mem_to_periph_initialize(struct dma_ring_buffer_to_periph *d
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t calculate_ring_buffer_fill_level(size_t buffer_size, size_t get_idx, size_t put_idx)
|
|
||||||
{
|
|
||||||
size_t fill_level;
|
|
||||||
|
|
||||||
if (put_idx >= get_idx) {
|
|
||||||
fill_level = (put_idx - get_idx);
|
|
||||||
} else {
|
|
||||||
fill_level = buffer_size - get_idx + put_idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fill_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void queue_or_start_dma_transfer(struct dma_ring_buffer_to_periph *buff)
|
static void queue_or_start_dma_transfer(struct dma_ring_buffer_to_periph *buff)
|
||||||
{
|
{
|
||||||
uint32_t dma_transfer_cnt;
|
uint32_t dma_transfer_cnt;
|
||||||
@ -289,4 +302,14 @@ void dma_ring_buffer_mem_to_periph_stop(struct dma_ring_buffer_to_periph *buff)
|
|||||||
memset(buff, 0, sizeof(struct dma_ring_buffer_to_periph));
|
memset(buff, 0, sizeof(struct dma_ring_buffer_to_periph));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dma_ring_buffer_mem_to_periph_fill_level(struct dma_ring_buffer_to_periph *buff, size_t *fill_level)
|
||||||
|
{
|
||||||
|
if (!buff || !fill_level)
|
||||||
|
return -1000;
|
||||||
|
|
||||||
|
*fill_level = calculate_ring_buffer_fill_level(buff->buffer_count, buff->dma_get_idx_current, buff->sw_put_idx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -86,6 +86,15 @@ int uart_init(struct stm_uart *uart)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uart_change_brr(struct stm_uart *uart, uint32_t brr)
|
||||||
|
{
|
||||||
|
if (!uart || !uart->uart_dev)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uart->brr_val = brr;
|
||||||
|
uart->uart_dev->BRR = brr;
|
||||||
|
}
|
||||||
|
|
||||||
void uart_disable(struct stm_uart *uart)
|
void uart_disable(struct stm_uart *uart)
|
||||||
{
|
{
|
||||||
if (!uart)
|
if (!uart)
|
||||||
@ -153,6 +162,16 @@ int uart_receive_data_with_dma(struct stm_uart *uart, const char **data, size_t
|
|||||||
return dma_ring_buffer_periph_to_mem_get_data(&uart->rx_ring_buff, (const volatile void **)data, len);
|
return dma_ring_buffer_periph_to_mem_get_data(&uart->rx_ring_buff, (const volatile void **)data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char uart_get_char(struct stm_uart *uart)
|
||||||
|
{
|
||||||
|
if (!uart)
|
||||||
|
return 0;
|
||||||
|
/* Wait for data to be available */
|
||||||
|
while (!(uart->uart_dev->SR & USART_SR_RXNE));
|
||||||
|
|
||||||
|
return (char)uart->uart_dev->DR;
|
||||||
|
}
|
||||||
|
|
||||||
int uart_check_rx_avail(struct stm_uart *uart)
|
int uart_check_rx_avail(struct stm_uart *uart)
|
||||||
{
|
{
|
||||||
if (!uart)
|
if (!uart)
|
||||||
@ -172,3 +191,26 @@ void uart_tx_dma_complete_int_callback(struct stm_uart *uart)
|
|||||||
dma_ring_buffer_mem_to_periph_int_callback(&uart->tx_ring_buff);
|
dma_ring_buffer_mem_to_periph_int_callback(&uart->tx_ring_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t uart_dma_tx_queue_avail(struct stm_uart *uart)
|
||||||
|
{
|
||||||
|
size_t fill_level = 0UL;
|
||||||
|
|
||||||
|
if (!uart)
|
||||||
|
return 0UL;
|
||||||
|
|
||||||
|
(void)dma_ring_buffer_mem_to_periph_fill_level(&uart->tx_ring_buff, &fill_level);
|
||||||
|
|
||||||
|
return fill_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t uart_dma_rx_queue_avail(struct stm_uart *uart)
|
||||||
|
{
|
||||||
|
size_t fill_level = 0UL;
|
||||||
|
|
||||||
|
if (!uart)
|
||||||
|
return 0UL;
|
||||||
|
|
||||||
|
(void)dma_ring_buffer_periph_to_mem_fill_level(&uart->rx_ring_buff, &fill_level);
|
||||||
|
|
||||||
|
return fill_level;
|
||||||
|
}
|
||||||
|
@ -41,6 +41,11 @@ void systick_wait_ms(uint32_t ms)
|
|||||||
while (wait_tick_ms < ms);
|
while (wait_tick_ms < ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t systick_get_global_tick()
|
||||||
|
{
|
||||||
|
return global_tick_ms;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interrupt Handler for SysTick
|
* @brief Interrupt Handler for SysTick
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user