From 73a76acef4aa14b042c9c56eef0fd19164afff42 Mon Sep 17 00:00:00 2001 From: sowgro Date: Mon, 22 Sep 2025 23:40:06 -0400 Subject: Submit endian converters --- project/Core/Src/Activties/activity4.c | 26 ------------------- project/Core/Src/Activties/midi_header.c | 37 +++++++++++++++++++++++++++ project/Core/Src/Homework/endian_converters.c | 16 ++++++++++++ project/Core/Src/main.c | 1 + 4 files changed, 54 insertions(+), 26 deletions(-) delete mode 100644 project/Core/Src/Activties/activity4.c create mode 100644 project/Core/Src/Activties/midi_header.c create mode 100644 project/Core/Src/Homework/endian_converters.c (limited to 'project/Core/Src') diff --git a/project/Core/Src/Activties/activity4.c b/project/Core/Src/Activties/activity4.c deleted file mode 100644 index c6b9b22..0000000 --- a/project/Core/Src/Activties/activity4.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * activity4.c - * - * Created on: Sep 16, 2025 - * Author: sowgro - */ - -#include "song.h" -#include - -typedef struct { - char chunk_type[4]; - unsigned int length; - unsigned short format; - unsigned short ntrcks; - unsigned short division; -} header; - -void run() { - header* p_header; - - p_header = (header *) (get_song(0).p_song); - - printf("type: %s, length: %u, format: %u, trackCount: %u, division: %u\r\n", p_header->chunk_type, p_header->length, p_header->format, p_header->ntrcks, p_header->division); -} - diff --git a/project/Core/Src/Activties/midi_header.c b/project/Core/Src/Activties/midi_header.c new file mode 100644 index 0000000..de3dc68 --- /dev/null +++ b/project/Core/Src/Activties/midi_header.c @@ -0,0 +1,37 @@ +/* + * activity4.c + * + * Created on: Sep 16, 2025 + * Author: sowgro + */ + +#include "song.h" +#include +#include +#include + +typedef struct { + char chunk_type[4]; + uint32_t length; + uint16_t format; + uint16_t ntrcks; + uint16_t division; +} header; + +void run() { + header* p_header; + + p_header = (header *) (get_song(0).p_song); + + p_header->length = convert_to_uint32((uint8_t*) &p_header->length); + p_header->format = convert_to_uint16((uint8_t*) &p_header->format); + p_header->ntrcks = convert_to_uint16((uint8_t*) &p_header->ntrcks); + p_header->division = convert_to_uint16((uint8_t*) &p_header->division); + + printf ("Header: \r\n"); + printf ("\tLength: %lu\r\n", p_header->length); + printf ("\tFormat: %u\r\n", p_header->format); + printf ("\tNum Tracks: %u\r\n", p_header->ntrcks); + printf ("\tDivision: %u\r\n", p_header->division); +} + diff --git a/project/Core/Src/Homework/endian_converters.c b/project/Core/Src/Homework/endian_converters.c new file mode 100644 index 0000000..1dbb5f7 --- /dev/null +++ b/project/Core/Src/Homework/endian_converters.c @@ -0,0 +1,16 @@ +/* + * endian_converters.c + * + * Created on: Sep 22, 2025 + * Author: sowgro + */ + +#include + +uint16_t convert_to_uint16 (uint8_t* p_value) { + return (p_value[0] << 8) + p_value[1]; +} + +uint32_t convert_to_uint32 (uint8_t* p_value) { + return (p_value[0] << 24) + (p_value[1] << 16) + (p_value[2] << 8) + p_value[3]; +} diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c index 247ed1c..8d76d3a 100644 --- a/project/Core/Src/main.c +++ b/project/Core/Src/main.c @@ -8,6 +8,7 @@ #include "LED.h" #include "UART.h" #include "demo.h" +#include "midi_header.h" #include -- cgit v1.2.3