global (minor): add spaces around operators for readability

This commit is contained in:
King Kévin 2019-04-02 19:51:18 +02:00
parent d7cd572f9a
commit 9220dbeb50
1 changed files with 15 additions and 15 deletions

View File

@ -15,7 +15,7 @@
/** global definitions and methods (code)
* @file global.c
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016-2017
* @date 2016-2019
*/
/* standard libraries */
#include <stdint.h> // standard integer types
@ -43,8 +43,8 @@ static volatile uint32_t sleep_duration = 0; /**< sleep duration count down (in
char* b2s(uint64_t binary, uint8_t rjust)
{
static char string[64+1] = {0}; // the string representation to return
uint8_t bit = LENGTH(string)-1; // the index of the bit to print
static char string[64 + 1] = {0}; // the string representation to return
uint8_t bit = LENGTH(string) - 1; // the index of the bit to print
string[bit--] = '\0'; // terminate string
while (binary) {
@ -56,7 +56,7 @@ char* b2s(uint64_t binary, uint8_t rjust)
binary >>= 1;
}
while (64-bit-1<rjust && bit>0) {
while (64 - bit - 1 < rjust && bit > 0) {
string[bit--] = '0';
}
@ -102,14 +102,14 @@ void led_toggle(void)
void sleep_us(uint32_t duration)
{
systick_counter_disable(); // disable SysTick to reconfigure it
if (!systick_set_frequency(1000000,rcc_ahb_frequency)) { // set SysTick frequency to microseconds
if (!systick_set_frequency(1000000, rcc_ahb_frequency)) { // set SysTick frequency to microseconds
while (true); // unhandled error
}
systick_clear(); // reset SysTick
systick_interrupt_enable(); // enable interrupt to count duration
sleep_duration = duration; // save sleep duration for count down
systick_counter_enable(); // start counting
while (sleep_duration>0) { // wait for count down to complete
while (sleep_duration > 0) { // wait for count down to complete
__WFI(); // go to sleep
}
}
@ -117,14 +117,14 @@ void sleep_us(uint32_t duration)
void sleep_ms(uint32_t duration)
{
systick_counter_disable(); // disable SysTick to reconfigure it
if (!systick_set_frequency(1000,rcc_ahb_frequency)) { // set SysTick frequency to milliseconds
if (!systick_set_frequency(1000, rcc_ahb_frequency)) { // set SysTick frequency to milliseconds
while (true); // unhandled error
}
systick_clear(); // reset SysTick
systick_interrupt_enable(); // enable interrupt to count duration
sleep_duration = duration; // save sleep duration for count down
systick_counter_enable(); // start counting
while (sleep_duration>0) { // wait for count down to complete
while (sleep_duration > 0) { // wait for count down to complete
__WFI(); // go to sleep
}
}
@ -132,10 +132,10 @@ void sleep_ms(uint32_t duration)
/** SysTick interrupt handler */
void sys_tick_handler(void)
{
if (sleep_duration>0) {
if (sleep_duration > 0) {
sleep_duration--; // decrement duration
}
if (0==sleep_duration) { // sleep complete
if (0 == sleep_duration) { // sleep complete
systick_counter_disable(); // stop systick
systick_interrupt_disable(); // stop interrupting
sleep_duration = 0; // ensure it still is at 0
@ -148,20 +148,20 @@ char user_input_get(void)
__WFI(); // go to sleep
}
volatile char to_return = user_input_buffer[user_input_i]; // get the next available character
user_input_i = (user_input_i+1)%LENGTH(user_input_buffer); // update used buffer
user_input_i = (user_input_i + 1) % LENGTH(user_input_buffer); // update used buffer
user_input_used--; // update used buffer
user_input_available = (user_input_used!=0); // update available data
user_input_available = (user_input_used != 0); // update available data
return to_return;
}
void user_input_store(char c)
{
// only save data if there is space in the buffer
if (user_input_used>=LENGTH(user_input_buffer)) { // if buffer is full
user_input_i = (user_input_i+1)%LENGTH(user_input_buffer); // drop oldest data
if (user_input_used >= LENGTH(user_input_buffer)) { // if buffer is full
user_input_i = (user_input_i + 1) % LENGTH(user_input_buffer); // drop oldest data
user_input_used--; // update used buffer information
}
user_input_buffer[(user_input_i+user_input_used)%LENGTH(user_input_buffer)] = c; // put character in buffer
user_input_buffer[(user_input_i + user_input_used) % LENGTH(user_input_buffer)] = c; // put character in buffer
user_input_used++; // update used buffer
user_input_available = true; // update available data
}