diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-11-20 00:07:38 -0500 |
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-11-20 00:07:38 -0500 |
| commit | c514f8fe3c3b25aa610139fb79c58a236e8149de (patch) | |
| tree | 525270ffcdf06768b387a2dd9d05131a2cda3c6e /project/Core/Src/Homework/hw8.c | |
| parent | cff905096851398315b22dca341e89ab657f12d8 (diff) | |
| download | 340-repo-Sowgro-c514f8fe3c3b25aa610139fb79c58a236e8149de.tar.gz 340-repo-Sowgro-c514f8fe3c3b25aa610139fb79c58a236e8149de.tar.bz2 340-repo-Sowgro-c514f8fe3c3b25aa610139fb79c58a236e8149de.zip | |
complete hw 8
Diffstat (limited to 'project/Core/Src/Homework/hw8.c')
| -rw-r--r-- | project/Core/Src/Homework/hw8.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/project/Core/Src/Homework/hw8.c b/project/Core/Src/Homework/hw8.c new file mode 100644 index 0000000..e684c07 --- /dev/null +++ b/project/Core/Src/Homework/hw8.c @@ -0,0 +1,31 @@ +/* + * hw8.c + * + * Created on: Nov 19, 2025 + * Author: sowgro + */ + +#include <stdint.h> +#include <stdio.h> +#include "hw8.h" + +void hw8_run() { + uint8_t data[] = {0x90, 0x82, 0x93, 0x64, 0xD3, 0x89}; + parseDelay_result_t d = parseDelay(data); + printf("delay: %lu bytes: %i\r\n", d.value, d.bytes_used); +} + +parseDelay_result_t parseDelay(uint8_t* delay) { + uint32_t ret = 0; + uint8_t* cur = delay; + + for (;;) { + uint8_t value = *cur & ~(1 << 7); + ret = (ret << 7) | value; + if (~*cur & (1 << 7)) { + break; + } + cur++; + } + return (parseDelay_result_t) {ret, cur - delay + 1}; +} |
