Объединить протокол терминала TMS2812 для Python и Android

This commit is contained in:
2026-10-01 15:41:43 +03:00
parent e3e30fdad7
commit 3457657979
14 changed files with 729 additions and 9 deletions

View File

@@ -3,8 +3,40 @@
#include "tms2812.h"
static int test_terminal(void)
{
uint8_t output[20], digits[12] = {0x81, 2, 4, 8, 9, 0x20, 0x10, 0x20, 0x40, 0x80, 3, 4};
const uint8_t ping[] = {0x0a, 0x38, 0, 1, 0, 0, 0xf0, 0xb4};
uint8_t reply[] = {0x0a, 0x38, 0x65, 0xa5, 0, 0, 0xaf, 0x9b, 0, 0};
const uint8_t test_prefix[] = {7, 66, 25, 0, 18, 0};
size_t size;
if (tms2812_build_memory_request(10, 0, 0, 0, output, sizeof output) != 8U ||
memcmp(output, ping, sizeof ping) != 0) return 10;
if (tms2812_build_memory_request(10, TMS2812_CMD_POKE, 0x12345678UL, 0xABCD,
output, sizeof output) != 12U || output[2] != 0x78 || output[5] != 0x12 ||
output[6] != 0xCD || output[7] != 0xAB || output[8] != 0 || output[9] != 0 ||
tms2812_crc16(output, 12U) != 0U) return 11;
if (tms2812_build_memory_request(10, 99, 0, 0, output, sizeof output) != 0U ||
tms2812_build_memory_request(10, 56, 0, 0, output, 7) != 0U) return 12;
if (tms2812_build_test_request(7, 25, 18, digits, 12, output, sizeof output) != 20U ||
memcmp(output, test_prefix, sizeof test_prefix) || memcmp(output + 6, digits, 12) ||
tms2812_crc16(output, 20) != 0U) return 13;
if (tms2812_build_test_request(7, 25, 18, digits, 11, output, sizeof output) != 0U ||
tms2812_build_fixed_request(7, 65, NULL, 1, output, sizeof output) != 0U) return 14;
for (size = 8; size <= 10; ++size)
if (tms2812_validate_response(reply, size, 10, 56, 10, 1) != TMS2812_OK) return 15;
if (tms2812_validate_response(reply, 7, 10, 56, 10, 1) != TMS2812_ERROR_LENGTH ||
tms2812_validate_response(reply, 8, 10, 56, 10, 0) != TMS2812_ERROR_LENGTH ||
tms2812_validate_response(reply, 10, 11, 56, 10, 1) != TMS2812_ERROR_HEADER) return 16;
reply[2] ^= 1;
if (tms2812_validate_response(reply, 10, 10, 56, 10, 1) != TMS2812_ERROR_CRC) return 17;
return 0;
}
int main(void)
{
int terminal_status = test_terminal();
if (terminal_status != 0) return terminal_status;
uint8_t request[TMS2812_UPLOAD_REQUEST_SIZE];
static const uint8_t prefix[] = {
0x05U, 0x34U, 0x78U, 0x56U, 0x34U, 0x12U,