diff options
author | Lisin Dmitriy <d.lisin@thirdpin.ru> | 2019-06-07 15:31:32 +0300 |
---|---|---|
committer | Lisin Dmitriy <d.lisin@thirdpin.ru> | 2019-06-07 15:31:32 +0300 |
commit | ad9af406e25eb137e70b1792c1ed140cb2d893fd (patch) | |
tree | 2a424cadb7375d60d54ea75ad5844e8914119f08 | |
parent | 2b3020e4f4aae4c5d621d9e871eef5df6e5aabde (diff) | |
parent | a3e279404856eccea518ddb1a6c3d32bb8b4bb01 (diff) |
Merge branch 'better_cmake_structure'release/v.2.2.0_07.06.2019
-rw-r--r-- | CMakeLists.txt | 30 | ||||
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | cm3cpp/adc.cpp (renamed from cm3cpp_adc.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/adc.hpp (renamed from cm3cpp_adc.h) | 0 | ||||
-rw-r--r-- | cm3cpp/adc_dma.cpp (renamed from cm3cpp_adc_dma.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/adc_dma.hpp (renamed from cm3cpp_adc_dma.h) | 2 | ||||
-rw-r--r-- | cm3cpp/dma.cpp (renamed from cm3cpp_dma.cpp) | 10 | ||||
-rw-r--r-- | cm3cpp/dma.hpp (renamed from cm3cpp_dma.hpp) | 12 | ||||
-rw-r--r-- | cm3cpp/extra/one_wire.cpp (renamed from extra/one_wire.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/extra/one_wire.hpp (renamed from extra/one_wire.h) | 4 | ||||
-rw-r--r-- | cm3cpp/flash_cycle.hpp (renamed from cm3cpp_flash_cycle.hpp) | 0 | ||||
-rw-r--r-- | cm3cpp/flash_otp.hpp (renamed from cm3cpp_flash_otp.hpp) | 0 | ||||
-rw-r--r-- | cm3cpp/gpio.cpp (renamed from cm3cpp_gpio.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/gpio.hpp (renamed from cm3cpp_gpio.h) | 0 | ||||
-rw-r--r-- | cm3cpp/i2c.cpp (renamed from cm3cpp_i2c.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/i2c.hpp (renamed from cm3cpp_i2c.h) | 4 | ||||
-rw-r--r-- | cm3cpp/irq/gen_irq.py (renamed from irq/gen_irq.py) | 0 | ||||
-rw-r--r-- | cm3cpp/irq/irq.cpp (renamed from irq/cm3cpp_irq.cpp) | 4 | ||||
-rw-r--r-- | cm3cpp/irq/irq.hpp (renamed from irq/cm3cpp_irq.h) | 0 | ||||
-rw-r--r-- | cm3cpp/private/assert.h (renamed from private/assert.h) | 0 | ||||
-rw-r--r-- | cm3cpp/private/pinout.h (renamed from private/pinout.h) | 0 | ||||
-rw-r--r-- | cm3cpp/rs485.cpp (renamed from rs485.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/rs485.hpp (renamed from rs485.h) | 4 | ||||
-rw-r--r-- | cm3cpp/spi.cpp (renamed from cm3cpp_spi.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/spi.hpp (renamed from cm3cpp_spi.h) | 4 | ||||
-rw-r--r-- | cm3cpp/systick.cpp (renamed from cm3cpp_systick.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/systick.hpp (renamed from cm3cpp_systick.h) | 0 | ||||
-rw-r--r-- | cm3cpp/timer.cpp (renamed from cm3cpp_timer.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/timer.hpp (renamed from cm3cpp_timer.h) | 0 | ||||
-rw-r--r-- | cm3cpp/usart.cpp (renamed from cm3cpp_usart.cpp) | 252 | ||||
-rw-r--r-- | cm3cpp/usart.hpp (renamed from cm3cpp_usart.h) | 412 | ||||
-rw-r--r-- | cm3cpp/usart_rb.cpp (renamed from cm3cpp_usart_rb.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/usart_rb.hpp (renamed from cm3cpp_usart_rb.h) | 4 | ||||
-rw-r--r-- | cm3cpp/utils/round_buffer.cpp (renamed from utils/round_buffer.cpp) | 2 | ||||
-rw-r--r-- | cm3cpp/utils/round_buffer.hpp (renamed from utils/round_buffer.h) | 0 |
35 files changed, 384 insertions, 382 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4430981..2371226 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,23 +5,23 @@ project(cm3cpp LANGUAGES C CXX ASM) add_library(${PROJECT_NAME} INTERFACE) target_sources(${PROJECT_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/extra/one_wire.cpp - ${CMAKE_CURRENT_LIST_DIR}/irq/cm3cpp_irq.cpp - ${CMAKE_CURRENT_LIST_DIR}/utils/round_buffer.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_adc_dma.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_adc.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_gpio.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_i2c.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_spi.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_systick.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_timer.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_usart_rb.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_usart.cpp - ${CMAKE_CURRENT_LIST_DIR}/rs485.cpp - ${CMAKE_CURRENT_LIST_DIR}/cm3cpp_dma.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/extra/one_wire.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/irq/irq.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/utils/round_buffer.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/adc_dma.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/adc.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/gpio.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/i2c.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/spi.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/systick.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/timer.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/usart_rb.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/usart.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/rs485.cpp + ${CMAKE_CURRENT_LIST_DIR}/cm3cpp/dma.cpp ) target_include_directories(${PROJECT_NAME} INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/../ + ${CMAKE_CURRENT_LIST_DIR} )
\ No newline at end of file @@ -24,7 +24,7 @@ Library supports only F2 and F4 microcontrollers. Library defines: ================ - - ``CM3CPP_CUSTOM_SYSTICK`` — disable library sysick realization + - ``CM3CPP_CUSTOM_SYSTICK`` — disable library systick realization (enabled by default). If define enabled you could not use :cpp:`systick::Counter` class; diff --git a/cm3cpp_adc.cpp b/cm3cpp/adc.cpp index aaf06af..23779dd 100644 --- a/cm3cpp_adc.cpp +++ b/cm3cpp/adc.cpp @@ -1,4 +1,4 @@ -#include "cm3cpp_adc.h" +#include "adc.hpp" namespace cm3cpp { diff --git a/cm3cpp_adc.h b/cm3cpp/adc.hpp index 416a82e..416a82e 100644 --- a/cm3cpp_adc.h +++ b/cm3cpp/adc.hpp diff --git a/cm3cpp_adc_dma.cpp b/cm3cpp/adc_dma.cpp index 6374e77..1a7bb09 100644 --- a/cm3cpp_adc_dma.cpp +++ b/cm3cpp/adc_dma.cpp @@ -1,4 +1,4 @@ -#include "cm3cpp_adc_dma.h" +#include "adc_dma.hpp" namespace cm3cpp { diff --git a/cm3cpp_adc_dma.h b/cm3cpp/adc_dma.hpp index 68565cd..0c059ca 100644 --- a/cm3cpp_adc_dma.h +++ b/cm3cpp/adc_dma.hpp @@ -4,7 +4,7 @@ #include <cstring> #include <libopencm3/stm32/dma.h> -#include "cm3cpp_adc.h" +#include "adc.hpp" #include "private/assert.h" namespace cm3cpp { diff --git a/cm3cpp_dma.cpp b/cm3cpp/dma.cpp index 5f7ed46..6e89b2a 100644 --- a/cm3cpp_dma.cpp +++ b/cm3cpp/dma.cpp @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file cm3cpp_dma + * @file dma * @author * @version V1.0 * @date 05-2019 @@ -12,7 +12,7 @@ */ /* Includes ------------------------------------------------------------------*/ -#include "cm3cpp_dma.hpp" +#include "dma.hpp" // LIBOPENCM3 INCLUDES #include <libopencm3/cm3/nvic.h> @@ -33,10 +33,10 @@ Dma::Dma(const LowLevelConfig& config) : rcc_periph_clock_enable(RCC_DMA1); } else { - rcc_periph_clock_enable(RCC_DMA2); - } + rcc_periph_clock_enable(RCC_DMA2); + } - // Reset channel + // Reset channel dma_stream_reset(_dma_num, _stream); // Config DMA diff --git a/cm3cpp_dma.hpp b/cm3cpp/dma.hpp index 5f164a2..a55981b 100644 --- a/cm3cpp_dma.hpp +++ b/cm3cpp/dma.hpp @@ -1,6 +1,6 @@ /** ****************************************************************************** - * @file cm3cpp_dma.hpp + * @file dma.hpp * @author * @version V1.0 * @date 05-2019 @@ -131,15 +131,15 @@ class Dma void disable_stream() const; void set_data_counter(uint16_t len) const; - + void enable_irq() const; void disable_irq() const; protected: - Dma() = delete; /// Constructor default is delete - Dma(const Dma& a) = delete; /// Constructor copy is delete - Dma(Dma&& a) = delete; /// Constructor move is delete + Dma() = delete; /// Constructor default is delete + Dma(const Dma& a) = delete; /// Constructor copy is delete + Dma(Dma&& a) = delete; /// Constructor move is delete Dma& operator=(const Dma&) = delete; /// Operator copy is delete Dma& operator=(Dma&&) = delete; /// Operator move is delete @@ -153,4 +153,4 @@ class Dma } // namespace dma -} // namespace cm3cpp // namespace cm3cpp +} // namespace cm3cpp diff --git a/extra/one_wire.cpp b/cm3cpp/extra/one_wire.cpp index 451c9e2..e384908 100644 --- a/extra/one_wire.cpp +++ b/cm3cpp/extra/one_wire.cpp @@ -1,4 +1,4 @@ -#include "one_wire.h" +#include "one_wire.hpp" namespace cm3cpp { diff --git a/extra/one_wire.h b/cm3cpp/extra/one_wire.hpp index ceeab32..6ad1af4 100644 --- a/extra/one_wire.h +++ b/cm3cpp/extra/one_wire.hpp @@ -1,8 +1,8 @@ #ifndef EXTRA_ONE_WIRE_H_ #define EXTRA_ONE_WIRE_H_ -#include "../cm3cpp_gpio.h" -#include "../cm3cpp_timer.h" +#include "../gpio.hpp" +#include "../timer.hpp" #include <string.h> namespace cm3cpp { diff --git a/cm3cpp_flash_cycle.hpp b/cm3cpp/flash_cycle.hpp index 5dce3f8..5dce3f8 100644 --- a/cm3cpp_flash_cycle.hpp +++ b/cm3cpp/flash_cycle.hpp diff --git a/cm3cpp_flash_otp.hpp b/cm3cpp/flash_otp.hpp index 159d072..159d072 100644 --- a/cm3cpp_flash_otp.hpp +++ b/cm3cpp/flash_otp.hpp diff --git a/cm3cpp_gpio.cpp b/cm3cpp/gpio.cpp index 80d7185..fb9685c 100644 --- a/cm3cpp_gpio.cpp +++ b/cm3cpp/gpio.cpp @@ -23,7 +23,7 @@ GPIO C++ Wrapper of libopencm3 library for STM32F2, STM32F4 */ -#include "cm3cpp_gpio.h" +#include "gpio.hpp" namespace cm3cpp { diff --git a/cm3cpp_gpio.h b/cm3cpp/gpio.hpp index 340c6f2..340c6f2 100644 --- a/cm3cpp_gpio.h +++ b/cm3cpp/gpio.hpp diff --git a/cm3cpp_i2c.cpp b/cm3cpp/i2c.cpp index c2f7bd0..239ec93 100644 --- a/cm3cpp_i2c.cpp +++ b/cm3cpp/i2c.cpp @@ -23,7 +23,7 @@ I2C C++ Wrapper of libopencm3 library for STM32F2, STM32F4 */ -#include "cm3cpp_i2c.h" +#include "i2c.hpp" namespace cm3cpp { diff --git a/cm3cpp_i2c.h b/cm3cpp/i2c.hpp index 0d43d8b..f36e589 100644 --- a/cm3cpp_i2c.h +++ b/cm3cpp/i2c.hpp @@ -28,10 +28,10 @@ I2C C++ Wrapper of libopencm3 library for STM32F2, STM32F4 #include <libopencm3/stm32/i2c.h> -#include "cm3cpp_gpio.h" +#include "gpio.hpp" #include "private/assert.h" -#include "cm3cpp_systick.h" +#include "systick.hpp" namespace cm3cpp { diff --git a/irq/gen_irq.py b/cm3cpp/irq/gen_irq.py index 50fdad5..50fdad5 100644 --- a/irq/gen_irq.py +++ b/cm3cpp/irq/gen_irq.py diff --git a/irq/cm3cpp_irq.cpp b/cm3cpp/irq/irq.cpp index 1e1dd0d..bc7320a 100644 --- a/irq/cm3cpp_irq.cpp +++ b/cm3cpp/irq/irq.cpp @@ -1,4 +1,6 @@ -#include "cm3cpp_irq.h" +#include <cstdint> + +#include "irq.hpp" #define DEFINE_CALLBACK(cfunc, int_enum) \ void cfunc(void) \ diff --git a/irq/cm3cpp_irq.h b/cm3cpp/irq/irq.hpp index 1f09bdf..1f09bdf 100644 --- a/irq/cm3cpp_irq.h +++ b/cm3cpp/irq/irq.hpp diff --git a/private/assert.h b/cm3cpp/private/assert.h index 6ed494f..6ed494f 100644 --- a/private/assert.h +++ b/cm3cpp/private/assert.h diff --git a/private/pinout.h b/cm3cpp/private/pinout.h index ae42718..ae42718 100644 --- a/private/pinout.h +++ b/cm3cpp/private/pinout.h diff --git a/rs485.cpp b/cm3cpp/rs485.cpp index a38d6ff..ff7c338 100644 --- a/rs485.cpp +++ b/cm3cpp/rs485.cpp @@ -23,7 +23,7 @@ RS485 implementation, public interface */ -#include "rs485.h" +#include "rs485.hpp" namespace cm3cpp { diff --git a/rs485.h b/cm3cpp/rs485.hpp index d8d05e4..ea9865e 100644 --- a/rs485.h +++ b/cm3cpp/rs485.hpp @@ -36,9 +36,9 @@ RS485 implementation, public interface #include <libopencm3/stm32/f4/nvic.h> #endif -#include "cm3cpp_gpio.h" +#include "gpio.hpp" #include "private/assert.h" -#include "utils/round_buffer.h" +#include "utils/round_buffer.hpp" namespace cm3cpp { diff --git a/cm3cpp_spi.cpp b/cm3cpp/spi.cpp index 39eed40..e37c256 100644 --- a/cm3cpp_spi.cpp +++ b/cm3cpp/spi.cpp @@ -24,7 +24,7 @@ SPI C++ Wrapper of libopencm3 library for STM32F2, STM32F4 */ -#include "cm3cpp_spi.h" +#include "spi.hpp" namespace cm3cpp { diff --git a/cm3cpp_spi.h b/cm3cpp/spi.hpp index 0eb7d28..cbb4f13 100644 --- a/cm3cpp_spi.h +++ b/cm3cpp/spi.hpp @@ -29,8 +29,8 @@ SPI C++ Wrapper of libopencm3 library for STM32F2, STM32F4 #include <libopencm3/stm32/spi.h> -#include "cm3cpp_gpio.h" -#include "irq/cm3cpp_irq.h" +#include "gpio.hpp" +#include "irq/irq.hpp" namespace cm3cpp { diff --git a/cm3cpp_systick.cpp b/cm3cpp/systick.cpp index f68cd85..5e1c0e5 100644 --- a/cm3cpp_systick.cpp +++ b/cm3cpp/systick.cpp @@ -23,7 +23,7 @@ SYSTICK implementation, public interface */ -#include "cm3cpp_systick.h" +#include "systick.hpp" #ifndef CM3CPP_CUSTOM_SYSTICK static volatile uint32_t counter; diff --git a/cm3cpp_systick.h b/cm3cpp/systick.hpp index 7685d86..7685d86 100644 --- a/cm3cpp_systick.h +++ b/cm3cpp/systick.hpp diff --git a/cm3cpp_timer.cpp b/cm3cpp/timer.cpp index 5fc0586..e02b54b 100644 --- a/cm3cpp_timer.cpp +++ b/cm3cpp/timer.cpp @@ -23,7 +23,7 @@ TIM C++ Wrapper of libopencm3 library for STM32F2, STM32F4 */ -#include "cm3cpp_timer.h" +#include "timer.hpp" namespace cm3cpp { diff --git a/cm3cpp_timer.h b/cm3cpp/timer.hpp index 31b78a9..31b78a9 100644 --- a/cm3cpp_timer.h +++ b/cm3cpp/timer.hpp diff --git a/cm3cpp_usart.cpp b/cm3cpp/usart.cpp index 0c2e3e2..87b82bf 100644 --- a/cm3cpp_usart.cpp +++ b/cm3cpp/usart.cpp @@ -1,126 +1,126 @@ -/*
- * This file is part of the libopencm3_cpp_extensions project.
- * hosted at http://github.com/thirdpin/libopencm3_cpp_extensions
- *
- * Copyright (C) 2016 Third Pin LLC
- * Written by Anastasiia Lazareva <a.lazareva@thirdpin.ru>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
-USART C++ Wrapper of libopencm3 library for STM32F2, STM32F4
-*/
-
-#include "cm3cpp_usart.h"
-
-namespace cm3cpp {
-
-namespace usart {
-
-Usart::Usart(LowLevelConfig config, Settings settings)
-{
- init(config, settings);
-}
-
-void Usart::init(LowLevelConfig config, Settings settings)
-{
- _mode = settings.mode;
-
- switch (config.usart_number) {
- case 1:
- _usart = USART1;
- _usart_nvic = NVIC_USART1_IRQ;
- break;
- case 2:
- _usart = USART2;
- _usart_nvic = NVIC_USART2_IRQ;
- break;
- case 3:
- _usart = USART3;
- _usart_nvic = NVIC_USART3_IRQ;
- break;
- case 4:
- _usart = UART4;
- _usart_nvic = NVIC_UART4_IRQ;
- break;
- case 5:
- _usart = UART5;
- _usart_nvic = NVIC_UART5_IRQ;
- break;
- case 6:
- _usart = USART6;
- _usart_nvic = NVIC_USART6_IRQ;
- break;
- }
-
- set_settings(settings);
- usart_enable(_usart);
-
- if (_mode == Mode::RX or _mode == Mode::RX_TX) {
- _rx.init(config.rx);
-
- if ((config.usart_number >= 1) && (config.usart_number <= 3))
- _rx.set_af(Gpio::AltFuncNumber::AF7);
- else
- _rx.set_af(Gpio::AltFuncNumber::AF8);
-
- _rx.mode_setup(Gpio::Mode::ALTERNATE_FUNCTION, Gpio::PullMode::NO_PULL);
- _rx.set_output_options(Gpio::OutputType::PUSH_PULL,
- Gpio::Speed::MEDIUM_25MHz);
- }
-
- if (_mode == Mode::TX or _mode == Mode::RX_TX) {
- _tx.init(config.tx);
-
- if ((config.usart_number >= 1) && (config.usart_number <= 3))
- _tx.set_af(Gpio::AltFuncNumber::AF7);
- else
- _tx.set_af(Gpio::AltFuncNumber::AF8);
-
- _tx.mode_setup(Gpio::Mode::ALTERNATE_FUNCTION, Gpio::PullMode::NO_PULL);
- _tx.set_output_options(Gpio::OutputType::PUSH_PULL,
- Gpio::Speed::MEDIUM_25MHz);
- }
-
- nvic_set_priority(_usart_nvic, config.nvic_priority);
- nvic_enable_irq(_usart_nvic);
-}
-
-void Usart::deinit()
-{
- usart_disable(_usart);
- nvic_disable_irq(_usart_nvic);
-
- if (_mode == Mode::RX or _mode == Mode::RX_TX)
- _rx.mode_setup(Gpio::Mode::INPUT, Gpio::PullMode::NO_PULL);
-
- if (_mode == Mode::TX or _mode == Mode::RX_TX)
- _tx.mode_setup(Gpio::Mode::INPUT, Gpio::PullMode::NO_PULL);
-}
-
-void Usart::set_settings(Settings settings)
-{
- _mode = settings.mode;
- usart_set_baudrate(_usart, settings.baud_rate);
- usart_set_databits(_usart, settings.word_length);
- usart_set_stopbits(_usart, settings.stop_bits);
- usart_set_mode(_usart, settings.mode);
- usart_set_parity(_usart, settings.parity);
- usart_set_flow_control(_usart, settings.flow_control);
-}
-
-} // namespace usart
-
-} // namespace cm3cpp
+/* + * This file is part of the libopencm3_cpp_extensions project. + * hosted at http://github.com/thirdpin/libopencm3_cpp_extensions + * + * Copyright (C) 2016 Third Pin LLC + * Written by Anastasiia Lazareva <a.lazareva@thirdpin.ru> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* +USART C++ Wrapper of libopencm3 library for STM32F2, STM32F4 +*/ + +#include "usart.hpp" + +namespace cm3cpp { + +namespace usart { + +Usart::Usart(LowLevelConfig config, Settings settings) +{ + init(config, settings); +} + +void Usart::init(LowLevelConfig config, Settings settings) +{ + _mode = settings.mode; + + switch (config.usart_number) { + case 1: + _usart = USART1; + _usart_nvic = NVIC_USART1_IRQ; + break; + case 2: + _usart = USART2; + _usart_nvic = NVIC_USART2_IRQ; + break; + case 3: + _usart = USART3; + _usart_nvic = NVIC_USART3_IRQ; + break; + case 4: + _usart = UART4; + _usart_nvic = NVIC_UART4_IRQ; + break; + case 5: + _usart = UART5; + _usart_nvic = NVIC_UART5_IRQ; + break; + case 6: + _usart = USART6; + _usart_nvic = NVIC_USART6_IRQ; + break; + } + + set_settings(settings); + usart_enable(_usart); + + if (_mode == Mode::RX or _mode == Mode::RX_TX) { + _rx.init(config.rx); + + if ((config.usart_number >= 1) && (config.usart_number <= 3)) + _rx.set_af(Gpio::AltFuncNumber::AF7); + else + _rx.set_af(Gpio::AltFuncNumber::AF8); + + _rx.mode_setup(Gpio::Mode::ALTERNATE_FUNCTION, Gpio::PullMode::NO_PULL); + _rx.set_output_options(Gpio::OutputType::PUSH_PULL, + Gpio::Speed::MEDIUM_25MHz); + } + + if (_mode == Mode::TX or _mode == Mode::RX_TX) { + _tx.init(config.tx); + + if ((config.usart_number >= 1) && (config.usart_number <= 3)) + _tx.set_af(Gpio::AltFuncNumber::AF7); + else + _tx.set_af(Gpio::AltFuncNumber::AF8); + + _tx.mode_setup(Gpio::Mode::ALTERNATE_FUNCTION, Gpio::PullMode::NO_PULL); + _tx.set_output_options(Gpio::OutputType::PUSH_PULL, + Gpio::Speed::MEDIUM_25MHz); + } + + nvic_set_priority(_usart_nvic, config.nvic_priority); + nvic_enable_irq(_usart_nvic); +} + +void Usart::deinit() +{ + usart_disable(_usart); + nvic_disable_irq(_usart_nvic); + + if (_mode == Mode::RX or _mode == Mode::RX_TX) + _rx.mode_setup(Gpio::Mode::INPUT, Gpio::PullMode::NO_PULL); + + if (_mode == Mode::TX or _mode == Mode::RX_TX) + _tx.mode_setup(Gpio::Mode::INPUT, Gpio::PullMode::NO_PULL); +} + +void Usart::set_settings(Settings settings) +{ + _mode = settings.mode; + usart_set_baudrate(_usart, settings.baud_rate); + usart_set_databits(_usart, settings.word_length); + usart_set_stopbits(_usart, settings.stop_bits); + usart_set_mode(_usart, settings.mode); + usart_set_parity(_usart, settings.parity); + usart_set_flow_control(_usart, settings.flow_control); +} + +} // namespace usart + +} // namespace cm3cpp diff --git a/cm3cpp_usart.h b/cm3cpp/usart.hpp index c72e0b0..68f8bc5 100644 --- a/cm3cpp_usart.h +++ b/cm3cpp/usart.hpp @@ -1,206 +1,206 @@ -/*
- * This file is part of the libopencm3_cpp_extensions project.
- * hosted at http://github.com/thirdpin/libopencm3_cpp_extensions
- *
- * Copyright (C) 2016 Third Pin LLC
- * Written by Anastasiia Lazareva <a.lazareva@thirdpin.ru>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
-USART C++ Wrapper of libopencm3 library for STM32F2, STM32F4
-*/
-
-#ifndef CM3CPP_USART_H_
-#define CM3CPP_USART_H_
-
-// GENERAL INCLUDES
-#include <cstdint>
-
-// LIBOPENCM3 INCLUDES
-#include <libopencm3/stm32/usart.h>
-#ifdef STM32F2
-#include <libopencm3/stm32/f2/nvic.h>
-#endif
-#ifdef STM32F4
-#include <libopencm3/stm32/f4/nvic.h>
-#endif
-
-// CM3CPP INCLUDES
-#include "cm3cpp_gpio.h"
-#include "irq/cm3cpp_irq.h"
-#include "private/assert.h"
-
-namespace cm3cpp {
-
-namespace usart {
-
-enum DataBits : uint8_t
-{
- _8 = 8,
- _9 = 9
-};
-
-enum Mode : uint16_t
-{
- RX = USART_MODE_RX,
- TX = USART_MODE_TX,
- RX_TX = USART_MODE_TX_RX
-};
-
-enum StopBits : uint16_t
-{
- _0_5 = USART_STOPBITS_0_5,
- _1 = USART_STOPBITS_1,
- _1_5 = USART_STOPBITS_1_5,
- _2 = USART_STOPBITS_2
-};
-
-enum Parity : uint16_t
-{
- PAR_NONE = USART_PARITY_NONE,
- PAR_EVEN = USART_PARITY_EVEN,
- PAR_ODD = USART_PARITY_ODD
-};
-
-enum FlowControl : uint16_t
-{
- NONE = USART_FLOWCONTROL_NONE,
- RTS = USART_FLOWCONTROL_RTS,
- CTS = USART_FLOWCONTROL_CTS,
- RTS_CTS = USART_FLOWCONTROL_RTS_CTS
-};
-
-class Usart
-{
- public:
- using Gpio = gpio::Gpio;
-
- enum class Flag : uint16_t
- {
- TRANSMIT_COMPLETE = USART_SR_TC,
- TX_BUFFER_EMPTY = USART_SR_TXE,
- RX_NOT_EMPTY = USART_SR_RXNE,
- };
-
- struct Settings
- {
- uint32_t baud_rate;
- DataBits word_length;
- StopBits stop_bits;
- Parity parity;
- Mode mode;
- FlowControl flow_control;
- };
-
- struct LowLevelConfig
- {
- uint8_t usart_number;
- gpio::Gpio::Pinout tx;
- gpio::Gpio::Pinout rx;
- uint8_t nvic_priority;
- };
-
- Usart() = default;
-
- Usart(LowLevelConfig config, Settings settings);
-
- void init(LowLevelConfig config, Settings settings);
-
- void deinit();
-
- void set_settings(Settings settings);
-
- bool get_flag_status(Flag flag)
- {
- return usart_get_flag(_usart, (uint16_t)flag);
- }
-
- bool interrupt_source_rx()
- {
- return (((USART_CR1(_usart) & USART_CR1_RXNEIE) != 0) &&
- usart_get_flag(_usart, USART_SR_RXNE));
- }
-
- bool interrupt_source_tx()
- {
- return (((USART_CR1(_usart) & USART_CR1_TXEIE) != 0) &&
- usart_get_flag(_usart, USART_SR_TXE));
- }
-
- bool interrupt_source_TC()
- {
- return (((USART_CR1(_usart) & USART_CR1_TCIE) != 0) &&
- usart_get_flag(_usart, USART_SR_TC));
- }
-
- void clear_tc_flag() { USART_SR(_usart) = ~USART_SR_TC; }
-
- void enable_irq() { nvic_enable_irq(_usart_nvic); }
-
- void disable_irq() { nvic_disable_irq(_usart_nvic); }
-
- void enable_rx_interrupt() { usart_enable_rx_interrupt(_usart); }
-
- void enable_tx_interrupt() { usart_enable_tx_interrupt(_usart); }
-
- void enable_tc_interrupt() { USART_CR1(_usart) |= USART_CR1_TCIE; }
-
- void disable_rx_interrupt() { usart_disable_rx_interrupt(_usart); }
-
- void disable_tx_interrupt() { usart_disable_tx_interrupt(_usart); }
-
- void disable_tc_interrupt() { USART_CR1(_usart) &= ~USART_CR1_TCIE; }
-
- bool is_framing_error() { return (USART_SR(_usart) & USART_SR_FE) != 0; }
-
- bool is_overrun_error() { return (USART_SR(_usart) & USART_SR_IDLE) != 0; }
-
- bool is_any_error_occurred()
- {
- return (USART_SR(_usart) &
- (USART_SR_ORE | USART_SR_FE | USART_SR_PE | USART_SR_NE)) != 0;
- }
-
- uint32_t get_sr_reg() { return USART_SR(_usart); }
-
- bool is_data_received() { return (USART_SR(_usart) & USART_SR_RXNE) != 0; }
-
- bool is_data_sended() { return (USART_SR(_usart) & USART_SR_TXE) != 0; }
-
- void write_blocking(uint16_t data) { usart_send_blocking(_usart, data); }
-
- void write(uint16_t data) { usart_send(_usart, data); }
-
- uint16_t read() { return usart_recv(_usart); }
-
- uint16_t read_blocking() { return usart_recv_blocking(_usart); }
-
- auto get_irq() { return static_cast<Interrupt>(_usart_nvic); }
-
- protected:
- Gpio _rx;
- Gpio _tx;
- uint32_t _usart;
- uint32_t _usart_nvic;
-
- Mode _mode;
-};
-
-} // namespace usart
-
-} // namespace cm3cpp
-
-#endif /* CM3CPP_USART_H_ */
+/* + * This file is part of the libopencm3_cpp_extensions project. + * hosted at http://github.com/thirdpin/libopencm3_cpp_extensions + * + * Copyright (C) 2016 Third Pin LLC + * Written by Anastasiia Lazareva <a.lazareva@thirdpin.ru> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* +USART C++ Wrapper of libopencm3 library for STM32F2, STM32F4 +*/ + +#ifndef CM3CPP_USART_H_ +#define CM3CPP_USART_H_ + +// GENERAL INCLUDES +#include <cstdint> + +// LIBOPENCM3 INCLUDES +#include <libopencm3/stm32/usart.h> +#ifdef STM32F2 +#include <libopencm3/stm32/f2/nvic.h> +#endif +#ifdef STM32F4 +#include <libopencm3/stm32/f4/nvic.h> +#endif + +// CM3CPP INCLUDES +#include "gpio.hpp" +#include "irq/irq.hpp" +#include "private/assert.h" + +namespace cm3cpp { + +namespace usart { + +enum DataBits : uint8_t +{ + _8 = 8, + _9 = 9 +}; + +enum Mode : uint16_t +{ + RX = USART_MODE_RX, + TX = USART_MODE_TX, + RX_TX = USART_MODE_TX_RX +}; + +enum StopBits : uint16_t +{ + _0_5 = USART_STOPBITS_0_5, + _1 = USART_STOPBITS_1, + _1_5 = USART_STOPBITS_1_5, + _2 = USART_STOPBITS_2 +}; + +enum Parity : uint16_t +{ + PAR_NONE = USART_PARITY_NONE, + PAR_EVEN = USART_PARITY_EVEN, + PAR_ODD = USART_PARITY_ODD +}; + +enum FlowControl : uint16_t +{ + NONE = USART_FLOWCONTROL_NONE, + RTS = USART_FLOWCONTROL_RTS, + CTS = USART_FLOWCONTROL_CTS, + RTS_CTS = USART_FLOWCONTROL_RTS_CTS +}; + +class Usart +{ + public: + using Gpio = gpio::Gpio; + + enum class Flag : uint16_t + { + TRANSMIT_COMPLETE = USART_SR_TC, + TX_BUFFER_EMPTY = USART_SR_TXE, + RX_NOT_EMPTY = USART_SR_RXNE, + }; + + struct Settings + { + uint32_t baud_rate; + DataBits word_length; + StopBits stop_bits; + Parity parity; + Mode mode; + FlowControl flow_control; + }; + + struct LowLevelConfig + { + uint8_t usart_number; + gpio::Gpio::Pinout tx; + gpio::Gpio::Pinout rx; + uint8_t nvic_priority; + }; + + Usart() = default; + + Usart(LowLevelConfig config, Settings settings); + + void init(LowLevelConfig config, Settings settings); + + void deinit(); + + void set_settings(Settings settings); + + bool get_flag_status(Flag flag) + { + return usart_get_flag(_usart, (uint16_t)flag); + } + + bool interrupt_source_rx() + { + return (((USART_CR1(_usart) & USART_CR1_RXNEIE) != 0) && + usart_get_flag(_usart, USART_SR_RXNE)); + } + + bool interrupt_source_tx() + { + return (((USART_CR1(_usart) & USART_CR1_TXEIE) != 0) && + usart_get_flag(_usart, USART_SR_TXE)); + } + + bool interrupt_source_TC() + { + return (((USART_CR1(_usart) & USART_CR1_TCIE) != 0) && + usart_get_flag(_usart, USART_SR_TC)); + } + + void clear_tc_flag() { USART_SR(_usart) = ~USART_SR_TC; } + + void enable_irq() { nvic_enable_irq(_usart_nvic); } + + void disable_irq() { nvic_disable_irq(_usart_nvic); } + + void enable_rx_interrupt() { usart_enable_rx_interrupt(_usart); } + + void enable_tx_interrupt() { usart_enable_tx_interrupt(_usart); } + + void enable_tc_interrupt() { USART_CR1(_usart) |= USART_CR1_TCIE; } + + void disable_rx_interrupt() { usart_disable_rx_interrupt(_usart); } + + void disable_tx_interrupt() { usart_disable_tx_interrupt(_usart); } + + void disable_tc_interrupt() { USART_CR1(_usart) &= ~USART_CR1_TCIE; } + + bool is_framing_error() { return (USART_SR(_usart) & USART_SR_FE) != 0; } + + bool is_overrun_error() { return (USART_SR(_usart) & USART_SR_IDLE) != 0; } + + bool is_any_error_occurred() + { + return (USART_SR(_usart) & + (USART_SR_ORE | USART_SR_FE | USART_SR_PE | USART_SR_NE)) != 0; + } + + uint32_t get_sr_reg() { return USART_SR(_usart); } + + bool is_data_received() { return (USART_SR(_usart) & USART_SR_RXNE) != 0; } + + bool is_data_sended() { return (USART_SR(_usart) & USART_SR_TXE) != 0; } + + void write_blocking(uint16_t data) { usart_send_blocking(_usart, data); } + + void write(uint16_t data) { usart_send(_usart, data); } + + uint16_t read() { return usart_recv(_usart); } + + uint16_t read_blocking() { return usart_recv_blocking(_usart); } + + auto get_irq() { return static_cast<Interrupt>(_usart_nvic); } + + protected: + Gpio _rx; + Gpio _tx; + uint32_t _usart; + uint32_t _usart_nvic; + + Mode _mode; +}; + +} // namespace usart + +} // namespace cm3cpp + +#endif /* CM3CPP_USART_H_ */ diff --git a/cm3cpp_usart_rb.cpp b/cm3cpp/usart_rb.cpp index adb332d..62c4816 100644 --- a/cm3cpp_usart_rb.cpp +++ b/cm3cpp/usart_rb.cpp @@ -23,7 +23,7 @@ USART C++ Wrapper of libopencm3 library for STM32F2, STM32F4 */ -#include "cm3cpp_usart_rb.h" +#include "usart_rb.hpp" namespace cm3cpp { diff --git a/cm3cpp_usart_rb.h b/cm3cpp/usart_rb.hpp index b4b1391..23a5fd6 100644 --- a/cm3cpp_usart_rb.h +++ b/cm3cpp/usart_rb.hpp @@ -29,8 +29,8 @@ USART C++ Wrapper of libopencm3 library for STM32F2, STM32F4 /************************************************************************************************** * CM3CPP INCLUDES *************************************************************************************************/ -#include "cm3cpp_usart.h" -#include "utils/round_buffer.h" +#include "usart.hpp" +#include "utils/round_buffer.hpp" namespace cm3cpp { diff --git a/utils/round_buffer.cpp b/cm3cpp/utils/round_buffer.cpp index e554d9c..79edbcb 100644 --- a/utils/round_buffer.cpp +++ b/cm3cpp/utils/round_buffer.cpp @@ -24,7 +24,7 @@ ROUND BUFFER implementation, public interface */ -#include "round_buffer.h" +#include "round_buffer.hpp" namespace cm3cpp { diff --git a/utils/round_buffer.h b/cm3cpp/utils/round_buffer.hpp index ba28e76..ba28e76 100644 --- a/utils/round_buffer.h +++ b/cm3cpp/utils/round_buffer.hpp |