summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2015-05-04 10:07:47 +0200
committerNicolas Schodet2019-10-07 00:44:50 +0200
commit9fe68a0e7b216f8142d6b0423d5cf8fc08ec7091 (patch)
tree6325e2bdec2070c6f8063d4c55de189d2c9d4e0b
parenta91aa1aad65c5f5da38511175c79a72c019b271b (diff)
ucoo/hal: use enum class
-rw-r--r--ucoo/hal/gpio/gpio.stm32f4.cc6
-rw-r--r--ucoo/hal/gpio/gpio.stm32f4.hh10
-rw-r--r--ucoo/hal/uart/test/test_uart.cc4
-rw-r--r--ucoo/hal/uart/test/test_uart_disc.cc12
-rw-r--r--ucoo/hal/uart/uart.stm32.cc4
-rw-r--r--ucoo/hal/uart/uart.stm32.hh4
6 files changed, 21 insertions, 19 deletions
diff --git a/ucoo/hal/gpio/gpio.stm32f4.cc b/ucoo/hal/gpio/gpio.stm32f4.cc
index 1b46fd5..3ee060a 100644
--- a/ucoo/hal/gpio/gpio.stm32f4.cc
+++ b/ucoo/hal/gpio/gpio.stm32f4.cc
@@ -93,13 +93,15 @@ Gpio::output ()
void
Gpio::pull (Pull dir)
{
- GPIO_PUPDR (port_) = dmask_set (mask_, GPIO_PUPDR (port_), dir);
+ GPIO_PUPDR (port_) = dmask_set (mask_, GPIO_PUPDR (port_),
+ static_cast<uint32_t> (dir));
}
void
Gpio::speed (Speed s)
{
- GPIO_OSPEEDR (port_) = dmask_set (mask_, GPIO_OSPEEDR (port_), s);
+ GPIO_OSPEEDR (port_) = dmask_set (mask_, GPIO_OSPEEDR (port_),
+ static_cast<uint32_t> (s));
}
} // namespace ucoo
diff --git a/ucoo/hal/gpio/gpio.stm32f4.hh b/ucoo/hal/gpio/gpio.stm32f4.hh
index 325511e..01f3661 100644
--- a/ucoo/hal/gpio/gpio.stm32f4.hh
+++ b/ucoo/hal/gpio/gpio.stm32f4.hh
@@ -33,13 +33,13 @@ namespace ucoo {
class Gpio : public Io
{
public:
- enum Pull
+ enum class Pull : uint32_t
{
- PULL_NONE = GPIO_PUPD_NONE,
- PULL_UP = GPIO_PUPD_PULLUP,
- PULL_DOWN = GPIO_PUPD_PULLDOWN,
+ NONE = GPIO_PUPD_NONE,
+ UP = GPIO_PUPD_PULLUP,
+ DOWN = GPIO_PUPD_PULLDOWN,
};
- enum Speed
+ enum class Speed : uint32_t
{
SPEED_2MHZ = GPIO_OSPEED_2MHZ,
SPEED_25MHZ = GPIO_OSPEED_25MHZ,
diff --git a/ucoo/hal/uart/test/test_uart.cc b/ucoo/hal/uart/test/test_uart.cc
index 3f4a53b..6236938 100644
--- a/ucoo/hal/uart/test/test_uart.cc
+++ b/ucoo/hal/uart/test/test_uart.cc
@@ -49,8 +49,8 @@ main (int argc, const char **argv)
gpio_set_af (GPIOD, GPIO_AF8, GPIO2);
gpio_set_af (GPIOD, GPIO_AF7, GPIO8 | GPIO9);
ucoo::Uart u0 (2), u1 (4);
- u0.enable (38400, ucoo::Uart::EVEN, 1);
- u1.enable (38400, ucoo::Uart::EVEN, 1);
+ u0.enable (38400, ucoo::Uart::Parity::EVEN, 1);
+ u1.enable (38400, ucoo::Uart::Parity::EVEN, 1);
#endif
ucoo::Uart *u[] = { &u0, &u1 };
char buf[64];
diff --git a/ucoo/hal/uart/test/test_uart_disc.cc b/ucoo/hal/uart/test/test_uart_disc.cc
index 7efe9ce..3893f7e 100644
--- a/ucoo/hal/uart/test/test_uart_disc.cc
+++ b/ucoo/hal/uart/test/test_uart_disc.cc
@@ -56,9 +56,9 @@ main (int argc, const char **argv)
ucoo::Uart u1 (0);
ucoo::Uart u3 (2);
ucoo::Uart u4 (3);
- u1.enable (38400, ucoo::Uart::EVEN, 1);
- u3.enable (38400, ucoo::Uart::EVEN, 1);
- u4.enable (38400, ucoo::Uart::EVEN, 1);
+ u1.enable (38400, ucoo::Uart::Parity::EVEN, 1);
+ u3.enable (38400, ucoo::Uart::Parity::EVEN, 1);
+ u4.enable (38400, ucoo::Uart::Parity::EVEN, 1);
// For this test, shorten B6 & B7 to have a loopback on UART1, shorten C10
// & C11 to connect UART3 to UART4.
rcc_periph_clock_enable (RCC_GPIOB);
@@ -110,13 +110,13 @@ main (int argc, const char **argv)
u->write (buf, buf_i);
break;
case 'O':
- u->enable (38400, ucoo::Uart::ODD, 1);
+ u->enable (38400, ucoo::Uart::Parity::ODD, 1);
break;
case 'E':
- u->enable (38400, ucoo::Uart::EVEN, 1);
+ u->enable (38400, ucoo::Uart::Parity::EVEN, 1);
break;
case 'N':
- u->enable (38400, ucoo::Uart::NONE, 1);
+ u->enable (38400, ucoo::Uart::Parity::NONE, 1);
break;
default:
if (buf_i < static_cast<int> (sizeof (buf)))
diff --git a/ucoo/hal/uart/uart.stm32.cc b/ucoo/hal/uart/uart.stm32.cc
index b70b9fe..4b02bf6 100644
--- a/ucoo/hal/uart/uart.stm32.cc
+++ b/ucoo/hal/uart/uart.stm32.cc
@@ -117,9 +117,9 @@ Uart::enable (int speed, Parity parity, int stop_bits)
assert_unreachable ();
USART_CR3 (base) = 0;
uint32_t cr1 = USART_CR1_UE | USART_CR1_RXNEIE | USART_CR1_TE | USART_CR1_RE;
- if (parity != NONE)
+ if (parity != Parity::NONE)
cr1 |= USART_CR1_M | USART_CR1_PCE;
- if (parity == ODD)
+ if (parity == Parity::ODD)
cr1 |= USART_CR1_PS;
USART_CR1 (base) = cr1;
// Reset status.
diff --git a/ucoo/hal/uart/uart.stm32.hh b/ucoo/hal/uart/uart.stm32.hh
index 25d6f6e..1dd3d54 100644
--- a/ucoo/hal/uart/uart.stm32.hh
+++ b/ucoo/hal/uart/uart.stm32.hh
@@ -38,7 +38,7 @@ class Uart : public Stream
{
public:
/// Parity setting.
- enum Parity { ODD, EVEN, NONE };
+ enum class Parity { ODD, EVEN, NONE };
/// Default error character.
static const char default_error_char = '~';
public:
@@ -47,7 +47,7 @@ class Uart : public Stream
/// Shutdown UART.
~Uart ();
/// Enable and setup UART.
- void enable (int speed, Parity parity = NONE, int stop_bits = 1);
+ void enable (int speed, Parity parity = Parity::NONE, int stop_bits = 1);
/// Disable.
void disable ();
/// Change the error character.