Skip to content

Commit 015bffb

Browse files
committed
Merge branch 'develop' into master
2 parents a851ec0 + ecb1021 commit 015bffb

File tree

6 files changed

+39
-36
lines changed

6 files changed

+39
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
*.i
2020
*.ii
2121
*.s
22+
/.pio

lib/cpputils_avr/src/serial_port.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,14 @@ void SerialPort::end() {
7070
}
7171

7272
void SerialPort::flush() const {
73-
while (bit_is_clear(UCSR0A, TXC0)) {}
73+
while (bit_is_clear(UCSR0A, TXC0)) {
74+
}
7475
// if we get here the hardware finished tranmission (TXC is set)
7576
}
7677

7778
int16_t SerialPort::read() {
7879
ExecuteAtomic<std::is_same<uint8_t, rx_buf_idx_t>::value> x;
79-
const rx_buf_idx_t head {
80-
x([this]() {
81-
return rx_buf_head_;
82-
})
83-
};
80+
const rx_buf_idx_t head { x([this]() { return rx_buf_head_; }) };
8481

8582
if (head == rx_buf_tail_) {
8683
// if the head isn't ahead of the tail, we don't have any characters
@@ -90,17 +87,15 @@ int16_t SerialPort::read() {
9087
const rx_buf_idx_t new_tail { static_cast<rx_buf_idx_t>(static_cast<rx_buf_idx_t>(rx_buf_tail_ + 1U) % sizeof(rx_buffer_)) };
9188

9289
ExecuteAtomic<std::is_same<uint8_t, rx_buf_idx_t>::value> x;
93-
x([this, new_tail]() {
94-
rx_buf_tail_ = new_tail;
95-
});
90+
x([this, new_tail]() { rx_buf_tail_ = new_tail; });
9691

9792
return static_cast<int16_t>(c);
9893
}
9994
}
10095

10196
int16_t SerialPort::read(void* buffer, const size_t length) {
10297
uint8_t* ptr { reinterpret_cast<uint8_t*>(buffer) };
103-
size_t n { 0 };
98+
size_t n {};
10499
while (n < length) {
105100
const int16_t c { read() };
106101
if (c < 0) {
@@ -114,7 +109,8 @@ int16_t SerialPort::read(void* buffer, const size_t length) {
114109

115110
int16_t SerialPort::write(uint8_t data) const {
116111
/* wait for empty transmit buffer */
117-
while (! (UCSR0A & (1 << UDRE0))) {}
112+
while (!(UCSR0A & (1 << UDRE0))) {
113+
}
118114

119115
/* put data into buffer, sends the data */
120116
UDR0 = data;
@@ -127,11 +123,11 @@ int16_t SerialPort::write(uint8_t data) const {
127123

128124
int16_t SerialPort::write(const void* buffer, const size_t length) const {
129125
const uint8_t* ptr { reinterpret_cast<const uint8_t*>(buffer) };
130-
for (size_t i(0U); i < length; ++i) {
126+
for (size_t i {}; i < length; ++i) {
131127
write(*ptr++);
132128
}
133129
return length;
134-
}
130+
} // namespace avr
135131

136132
inline __attribute__((always_inline)) void SerialPort::isr() {
137133
if (bit_is_clear(UCSR0A, UPE0)) {

lib/cpputils_avr/src/serial_port.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* @note Based on Arduino implementation <https://github.com/arduino/ArduinoCore-avr>
2525
*/
2626

27-
#ifndef SRC_SERIAL_PORT_H_
28-
#define SRC_SERIAL_PORT_H_
27+
#pragma once
2928

3029
#include <cstdint>
3130
#include <cstddef>
@@ -53,7 +52,7 @@ class SerialPortBase {
5352
/**
5453
* @brief Construct a new SerialPortBase object
5554
*/
56-
SerialPortBase() : rx_buf_head_ { 0 }, rx_buf_tail_ { 0 } {}
55+
SerialPortBase() : rx_buf_head_ {}, rx_buf_tail_ {} {}
5756
};
5857

5958

@@ -158,5 +157,3 @@ class Uart0 {
158157
};
159158

160159
} /* namespace avr */
161-
162-
#endif /* SRC_SERIAL_PORT_H_ */

lib/cpputils_avr/src/utils_avr.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
* @date 15.04.2018
2424
*/
2525

26-
#ifndef SRC_UTILS_AVR_H_
27-
#define SRC_UTILS_AVR_H_
26+
#pragma once
2827

2928
#include <cstdint>
3029
#include <ostream>
@@ -42,7 +41,7 @@ namespace avr {
4241
class FlashStringHelper;
4342
#define F(string_literal) (reinterpret_cast<const avr::FlashStringHelper*>(PSTR(string_literal)))
4443

45-
inline std::ostream& operator <<(std::ostream& os, const avr::FlashStringHelper* v) {
44+
inline std::ostream& operator<<(std::ostream& os, const avr::FlashStringHelper* v) {
4645
auto ptr(reinterpret_cast<PGM_P>(v));
4746
while (true) {
4847
const uint8_t c { pgm_read_byte(ptr++) };
@@ -193,21 +192,21 @@ class IntLock {
193192
/**
194193
* @brief Deleted copy assignment operator to prohibit copies
195194
*/
196-
void operator =(const IntLock&) = delete;
195+
void operator=(const IntLock&) = delete;
197196
};
198197

199198
/**
200199
* @brief Specialization of constructor for ACTIVE == false
201200
* @note Does nothing
202201
*/
203-
template<>
202+
template <>
204203
inline IntLock<false>::IntLock() {}
205204

206205
/**
207206
* @brief Specialization of constructor for ACTIVE == true
208207
* @note Clears global interrupt flag
209208
*/
210-
template<>
209+
template <>
211210
inline IntLock<true>::IntLock() : sreg_ { SREG } {
212211
__builtin_avr_cli();
213212
}
@@ -228,11 +227,9 @@ struct ExecuteAtomic {
228227
*/
229228
template <typename F>
230229
auto operator()(F func) const -> decltype(func()) {
231-
IntLock<! FROM_ISR> lock;
230+
IntLock<!FROM_ISR> lock;
232231
return func();
233232
}
234233
};
235234

236235
} /* namespace avr */
237-
238-
#endif /* SRC_UTILS_AVR_H_ */

platformio.ini

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
; Please visit documentation for the other options and examples
99
; http://docs.platformio.org/page/projectconf.html
1010

11-
[env:1284p16m]
12-
platform = https://github.com/tsandmann/platform-atmelavr.git
11+
[platformio]
12+
default_envs = 1284p
13+
src_dir = src
14+
include_dir = src
15+
16+
[env:1284p]
17+
platform = atmelavr
1318
board = 1284p16m
1419
board_build.f_cpu = 16000000UL
1520
;board_build.f_cpu = 20000000UL
1621
;build_unflags = -std=gnu++11 -flto
1722
build_unflags = -std=gnu++11
18-
build_flags = -std=gnu++14 -Wextra
19-
;build_flags = -std=gnu++14
23+
build_flags = -std=gnu++17 -Wextra -Wmissing-declarations -Wshadow -Wformat=2 -Wconversion
2024
;build_flags = -std=gnu++14 -save-temps -fverbose-asm -dA
25+
26+
;upload_protocol = avr109
27+
;upload_flags = -u
28+
;upload_port = net:ctbot:10002

src/servo.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ class Servo {
5353
* @brief Create a servo instance for given servo ID
5454
* @param[in] num: ID of servo (ID::SERVO_1 or ID::SERVO_2)
5555
*/
56-
Servo(ID num) : Servo(num, num == ID::SERVO_1 ? PTR_8(CtBotConfig::SERVO_1_REG::DDR) : PTR_8(CtBotConfig::SERVO_2_REG::DDR),
57-
num == ID::SERVO_1 ? CtBotConfig::SERVO_1_PIN : CtBotConfig::SERVO_2_PIN, num == ID::SERVO_1 ? PTR_16(CtBotConfig::SERVO_1_OCR) : PTR_16(CtBotConfig::SERVO_2_OCR)) {}
56+
Servo(ID num)
57+
: Servo(num, num == ID::SERVO_1 ? PTR_8(CtBotConfig::SERVO_1_REG::DDR) : PTR_8(CtBotConfig::SERVO_2_REG::DDR),
58+
num == ID::SERVO_1 ? CtBotConfig::SERVO_1_PIN : CtBotConfig::SERVO_2_PIN,
59+
num == ID::SERVO_1 ? PTR_16(CtBotConfig::SERVO_1_OCR) : PTR_16(CtBotConfig::SERVO_2_OCR)) {}
5860

5961
/**
6062
* @brief Set the servo to a position
@@ -66,7 +68,9 @@ class Servo {
6668
* @brief Gets the last set servo position
6769
* @return Position of servo or POS_OFF, if servo turned off
6870
*/
69-
auto get() const { return position_; }
71+
auto get() const {
72+
return position_;
73+
}
7074

7175
protected:
7276
const ID id_; /**< Servo ID: ID::SERVO_1 or ID::SERVO_2 */
@@ -102,8 +106,8 @@ class Servo {
102106
}
103107

104108
private:
105-
static constexpr float TIMER_PRESCALER { 8.f }; /**< Prescaler for Timer2 (divider for CPU clock) to create servo PWM frequency */
106-
static constexpr float TIMER_MAX { 65535.f }; /**< Maximum value of Timer2 */
109+
static constexpr float TIMER_PRESCALER { 8.f }; /**< Prescaler for Timer3 (divider for CPU clock) to create servo PWM frequency */
110+
static constexpr float TIMER_MAX { 65535.f }; /**< Maximum value of Timer3 */
107111
static constexpr float TIMER_FACTOR { 1.f }; /**< Correction factor for timer output compare match value calculation */
108112
};
109113

0 commit comments

Comments
 (0)