Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use printf from libc #121

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions apps/battery-monitor/src/freertos-tasks.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "freertos-tasks.h"

#include <stdio.h>
#include <string.h>

#include "adc.h"
Expand All @@ -14,7 +15,6 @@
// STM32Common
#include "error.h"
#include "postmaster-hal.h"
#include "print.h"

// CK
#include "mayor.h"
Expand Down Expand Up @@ -157,7 +157,7 @@ void process_letter(void *unused) {
for (;;) {
if (HAL_CAN_ActivateNotification(&peripherals->common_peripherals->hcan,
CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) {
print("Error activating interrupt.\r\n");
printf("Error activating interrupt.\r\n");
error();
}
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
Expand All @@ -166,7 +166,7 @@ void process_letter(void *unused) {
while (HAL_CAN_GetRxMessage(&peripherals->common_peripherals->hcan,
CAN_RX_FIFO0, &header, data) == HAL_OK) {
if (ck_correct_letter_received() != CK_OK) {
print("CAN Kingdom error in ck_correct_letter_received().\r\n");
printf("CAN Kingdom error in ck_correct_letter_received().\r\n");
}
letter = frame_to_letter(&header, data);
dispatch_letter(&letter);
Expand Down Expand Up @@ -208,13 +208,13 @@ void send_docs(void) {
ck_data_t *ck_data = get_ck_data();

if (ck_send_document(ck_data->cell_folder->folder_no) != CK_OK) {
print("failed to send doc.\r\n");
printf("failed to send doc.\r\n");
}
if (ck_send_document(ck_data->reg_out_folder->folder_no) != CK_OK) {
print("failed to send doc.\r\n");
printf("failed to send doc.\r\n");
}
if (ck_send_document(ck_data->vbat_out_current_folder->folder_no) != CK_OK) {
print("failed to send doc.\r\n");
printf("failed to send doc.\r\n");
}
}

Expand All @@ -224,19 +224,19 @@ void dispatch_letter(ck_letter_t *letter) {
// Check for default letter
if (ck_is_default_letter(letter) == CK_OK) {
if (ck_default_letter_received() != CK_OK) {
print("CAN Kingdom error in ck_default_letter_received().\r\n");
printf("CAN Kingdom error in ck_default_letter_received().\r\n");
}
}
// Check for king's letter
else if (ck_is_kings_envelope(&letter->envelope) == CK_OK) {
if (ck_process_kings_letter(letter) != CK_OK) {
print("failed to process king's letter.\r\n");
printf("failed to process king's letter.\r\n");
}
}
// Check for any other letter
else if (ck_get_envelopes_folder(&letter->envelope, &folder) == CK_OK) {
if (handle_letter(folder, letter) != APP_OK) {
print("failed to process page.\r\n");
printf("failed to process page.\r\n");
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions apps/battery-monitor/src/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdio.h>

#include "ck-data.h"
#include "freertos-tasks.h"
#include "peripherals.h"
Expand All @@ -11,7 +13,6 @@
// STM32Common
#include "clock.h"
#include "error.h"
#include "print.h"

// FreeRTOS
#include "FreeRTOS.h"
Expand Down Expand Up @@ -39,7 +40,7 @@ int main(void) {
task_init();
mayor_init();

print("Starting application...\r\n");
printf("Starting application...\r\n");

// Start scheduler
vTaskStartScheduler();
Expand Down Expand Up @@ -79,7 +80,7 @@ void mayor_init(void) {
};

if (ck_mayor_init(&mayor) != CK_OK) {
print("Error setting up mayor.\r\n");
printf("Error setting up mayor.\r\n");
error();
}
}
Expand All @@ -88,7 +89,7 @@ void default_letter_timer_callback(TimerHandle_t timer) {
(void)timer;

if (ck_default_letter_timeout() != CK_OK) {
print("CAN Kingdom error in ck_default_letter_timeout().\r\n");
printf("CAN Kingdom error in ck_default_letter_timeout().\r\n");
}
}

Expand Down
4 changes: 2 additions & 2 deletions apps/joystick/src/main.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "app.h"
#include "clock.h"
#include "error.h"
#include "flash.h"
#include "peripherals.h"
#include "print.h"

// FreeRTOS
#include "FreeRTOS.h"
Expand Down Expand Up @@ -43,7 +43,7 @@ int main(void) {

task_init();

print("Starting application...\n");
printf("Starting application...\n");

// Start scheduler
vTaskStartScheduler();
Expand Down
31 changes: 13 additions & 18 deletions apps/sbus-receiver/src/freertos-tasks.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "freertos-tasks.h"

#include <stdio.h>
#include <string.h>

#include "ck-data.h"
Expand All @@ -13,8 +14,6 @@
// STM32Common
#include "error.h"
#include "peripherals.h"
#include "print.h"
#include "printf.h"

// FreeRTOS
#include "FreeRTOS.h"
Expand Down Expand Up @@ -87,13 +86,13 @@ void sbus_read(void *unused) {
// connection loss (heavy). This will be handled by the radio receiver,
// so we do nothing.
if (sbus_packet.failsafe_activated) {
print("Failsafe activated\r\n");
printf("Failsafe activated\r\n");
}

// Indicates slight connection loss or issue with frame.
// Also handled by the receiver.
if (sbus_packet.frame_lost) {
print("Frame lost\r\n");
printf("Frame lost\r\n");
}

steering_command = sbus_packet_to_steering_command(&sbus_packet);
Expand Down Expand Up @@ -122,9 +121,7 @@ int sbus_read_header(uint8_t *sbus_data) {
// Error check
uart_error = HAL_UART_GetError(&peripherals->huart2);
if (uart_error != HAL_UART_ERROR_NONE) {
char str[32]; // NOLINT
sprintf(str, "UART error in SBUS header: %u\r\n", uart_error);
print(str);
printf("UART error in SBUS header: %u\r\n", uart_error);
// Handle overrun by clearing receive register
if (uart_error == HAL_UART_ERROR_ORE) {
__HAL_UART_FLUSH_DRREGISTER(&peripherals->huart2);
Expand Down Expand Up @@ -162,9 +159,7 @@ int sbus_read_data(uint8_t *sbus_data) {
// Check for uart errors
uart_error = HAL_UART_GetError(&peripherals->huart2);
if (uart_error != HAL_UART_ERROR_NONE) {
char str[32]; // NOLINT
sprintf(str, "UART error in SBUS data: %u\r\n", uart_error);
print(str);
printf("UART error in SBUS data: %u\r\n", uart_error);
// Handle overrun by clearing receive register
if (uart_error == HAL_UART_ERROR_ORE) {
__HAL_UART_FLUSH_DRREGISTER(&peripherals->huart2);
Expand All @@ -188,16 +183,16 @@ void send_steering_command(steering_command_t *command) {
sizeof(command->throttle_trim));

if (ck_send_document(ck_data->steering_folder->folder_no) != CK_OK) {
print("failed to send doc.\r\n");
printf("failed to send doc.\r\n");
}
if (ck_send_document(ck_data->steering_trim_folder->folder_no) != CK_OK) {
print("failed to send doc.\r\n");
printf("failed to send doc.\r\n");
}
if (ck_send_document(ck_data->throttle_folder->folder_no) != CK_OK) {
print("failed to send doc.\r\n");
printf("failed to send doc.\r\n");
}
if (ck_send_document(ck_data->throttle_trim_folder->folder_no) != CK_OK) {
print("failed to send doc.\r\n");
printf("failed to send doc.\r\n");
}
}

Expand All @@ -213,7 +208,7 @@ void process_letter(void *unused) {
for (;;) {
if (HAL_CAN_ActivateNotification(&peripherals->common_peripherals->hcan,
CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) {
print("Error activating interrupt.\r\n");
printf("Error activating interrupt.\r\n");
error();
}
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
Expand All @@ -222,7 +217,7 @@ void process_letter(void *unused) {
while (HAL_CAN_GetRxMessage(&peripherals->common_peripherals->hcan,
CAN_RX_FIFO0, &header, data) == HAL_OK) {
if (ck_correct_letter_received() != CK_OK) {
print("CAN Kingdom error in ck_correct_letter_received().\r\n");
printf("CAN Kingdom error in ck_correct_letter_received().\r\n");
}
letter = frame_to_letter(&header, data);
dispatch_letter(&letter);
Expand All @@ -234,13 +229,13 @@ void dispatch_letter(ck_letter_t *letter) {
// Check for default letter
if (ck_is_default_letter(letter) == CK_OK) {
if (ck_default_letter_received() != CK_OK) {
print("CAN Kingdom error in ck_default_letter_received().\r\n");
printf("CAN Kingdom error in ck_default_letter_received().\r\n");
}
}
// Check for king's letter
else if (ck_is_kings_envelope(&letter->envelope) == CK_OK) {
if (ck_process_kings_letter(letter) != CK_OK) {
print("failed to process king's letter.\r\n");
printf("failed to process king's letter.\r\n");
}
}
// Check for any other letter
Expand Down
8 changes: 4 additions & 4 deletions apps/sbus-receiver/src/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdio.h>
#include <string.h>

#include "ck-data.h"
Expand All @@ -12,7 +13,6 @@
#include "clock.h"
#include "error.h"
#include "peripherals.h"
#include "print.h"

// FreeRTOS
#include "FreeRTOS.h"
Expand Down Expand Up @@ -41,7 +41,7 @@ int main(void) {
task_init();
mayor_init();

print("Starting application...\r\n");
printf("Starting application...\r\n");

// Start scheduler
vTaskStartScheduler();
Expand Down Expand Up @@ -81,7 +81,7 @@ void mayor_init(void) {
};

if (ck_mayor_init(&mayor) != CK_OK) {
print("Error setting up mayor.\r\n");
printf("Error setting up mayor.\r\n");
error();
}
}
Expand All @@ -90,7 +90,7 @@ void default_letter_timer_callback(TimerHandle_t timer) {
(void)timer;

if (ck_default_letter_timeout() != CK_OK) {
print("CAN Kingdom error in ck_default_letter_timeout().\r\n");
printf("CAN Kingdom error in ck_default_letter_timeout().\r\n");
}
}

Expand Down
1 change: 0 additions & 1 deletion apps/sbus-receiver/src/peripherals.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "error.h"
#include "ports.h"
#include "print.h"
#include "stm32f3xx_hal.h"

#define USART2_IRQ_PRIORITY 5
Expand Down
Loading