Start implementation of onewire temperature sensor interface

This commit is contained in:
Mario Hüttel 2020-02-24 20:02:37 +01:00
parent 26b8ad852e
commit 1ef7713351
6 changed files with 84 additions and 2 deletions

View File

@ -49,6 +49,8 @@ CFILES += rotary-encoder.c
CFILES += stack-check.c
CFILES += onewire-if.c onewire-temp-sensors.c
DEFINES += -DDEBUGBUILD
###################################################################################

View File

@ -23,7 +23,9 @@
#include <stm-periph/uart.h>
int onewire_if_init_uart(struct stm_uart *uart);
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);

View File

@ -18,8 +18,30 @@
* 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__ */

View File

@ -28,6 +28,7 @@
#define PINMASK(pin) ((0x3) << (pin * 2))
#define SETAF(PORT,PIN,AF) PORT->AFR[(PIN < 8 ? 0 : 1)] |= AF << ((PIN < 8 ? PIN : (PIN - 8)) * 4)
#define ANALOG(pin) (0x03 << (pin * 2))
#define OTYP_OPENDRAIN(pin) (0x1U << (pin))
#define BITMASK_TO_BITNO(x) (x&0x1?0:x&0x2?1:x&0x4?2:x&0x8?3: \
x&0x10?4:x&0x20?5:x&0x40?6:x&0x80?7: \

View File

@ -19,3 +19,38 @@
*/
#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)
{
}

View File

@ -18,5 +18,25 @@
* 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));
}