UART write example (#53)

* Rename test functions

* rewrite furi API, segfault

* make fixes in FURI, log through FURI

* add uart write example blank

* implement fuprintf instead of fopencookie

* add gif, blank page

* UART write example description

Co-authored-by: Vadim Kaushan <admin@disasm.info>
This commit is contained in:
coreglitch
2020-08-27 00:32:22 +06:00
committed by GitHub
parent 5094623d04
commit 4dc82b68d1
20 changed files with 392 additions and 195 deletions

View File

@@ -35,7 +35,7 @@ bool furi_create(const char* name, void* value, size_t size) {
if(current_buffer_idx >= MAX_RECORD_COUNT) {
// max record count exceed
#ifdef FURI_DEBUG
printf("[FURI] max record count exceed\n");
printf("[FURI] create: max record count exceed\n");
#endif
return NULL;
}
@@ -52,10 +52,12 @@ bool furi_create(const char* name, void* value, size_t size) {
records[current_buffer_idx].subscribers[i].allocated = false;
}
current_buffer_idx++;
return true;
}
FuriRecordHandler furi_open(
FuriRecordSubscriber* furi_open(
const char* name,
bool solo,
bool no_mute,
@@ -75,16 +77,15 @@ FuriRecordHandler furi_open(
printf("[FURI] cannot find record %s\n", name);
#endif
FuriRecordHandler res = {.record = NULL, .subscriber = NULL};
return res;
return NULL;
}
// allocate subscriber
FuriRecordSubscriber* subscriber = NULL;
for(size_t i = 0; i < MAX_RECORD_SUBSCRIBERS; i++) {
if(!records[current_buffer_idx].subscribers[i].allocated) {
subscriber = &records[current_buffer_idx].subscribers[i];
if(!record->subscribers[i].allocated) {
subscriber = &record->subscribers[i];
break;
}
}
@@ -92,11 +93,10 @@ FuriRecordHandler furi_open(
if(subscriber == NULL) {
// cannot add subscriber (full)
#ifdef FURI_DEBUG
printf("[FURI] cannot add subscriber (full)\n");
printf("[FURI] open: cannot add subscriber (full)\n");
#endif
FuriRecordHandler res = {.record = NULL, .subscriber = NULL};
return res;
return NULL;
}
// increase mute_counter
@@ -110,25 +110,31 @@ FuriRecordHandler furi_open(
subscriber->no_mute = no_mute;
subscriber->cb = value_callback;
subscriber->state_cb = state_callback;
subscriber->record = record;
// register record in application
FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle());
current_task->records[current_task->records_count] = record;
current_task->records_count++;
if(current_task != NULL) {
current_task->records[current_task->records_count] = record;
current_task->records_count++;
} else {
#ifdef FURI_DEBUG
printf("[FURI] open: no current task\n");
#endif
}
FuriRecordHandler res = {.record = record, .subscriber = subscriber};
return res;
return subscriber;
}
void furi_close(FuriRecordHandler* handler) {
void furi_close(FuriRecordSubscriber* handler) {
#ifdef FURI_DEBUG
printf("[FURI] closing %s record\n", handler->record->name);
#endif
// deallocate subscriber
handler->subscriber->allocated = false;
handler->allocated = false;
// set mute counter to next max value
uint8_t max_mute_counter = 0;
@@ -142,7 +148,7 @@ void furi_close(FuriRecordHandler* handler) {
handler->record->mute_counter = max_mute_counter;
}
static void furi_notify(FuriRecordHandler* handler, const void* value, size_t size) {
static void furi_notify(FuriRecordSubscriber* handler, const void* value, size_t size) {
for(size_t i = 0; i < MAX_RECORD_SUBSCRIBERS; i++) {
if(handler->record->subscribers[i].allocated) {
if(handler->record->subscribers[i].cb != NULL) {
@@ -152,17 +158,17 @@ static void furi_notify(FuriRecordHandler* handler, const void* value, size_t si
}
}
void* furi_take(FuriRecordHandler* handler) {
void* furi_take(FuriRecordSubscriber* handler) {
// take mutex
return handler->record->value;
}
void furi_give(FuriRecordHandler* handler) {
void furi_give(FuriRecordSubscriber* handler) {
// release mutex
}
bool furi_read(FuriRecordHandler* handler, void* value, size_t size) {
bool furi_read(FuriRecordSubscriber* handler, void* value, size_t size) {
#ifdef FURI_DEBUG
printf("[FURI] read from %s\n", handler->record->name);
#endif
@@ -182,23 +188,44 @@ bool furi_read(FuriRecordHandler* handler, void* value, size_t size) {
return true;
}
bool furi_write(FuriRecordHandler* handler, const void* value, size_t size) {
bool furi_write(FuriRecordSubscriber* handler, const void* value, size_t size) {
#ifdef FURI_DEBUG
printf("[FURI] write to %s\n", handler->record->name);
#endif
if(handler == NULL || handler->record == NULL || value == NULL) return false;
if(handler == NULL || handler->record == NULL || value == NULL) {
#ifdef FURI_DEBUG
printf("[FURI] write: null param %x %x\n", (uint32_t)(size_t)handler, (uint32_t)(size_t)value);
#endif
return false;
}
// check if closed
if(!handler->subscriber->allocated) return false;
if(!handler->allocated) {
#ifdef FURI_DEBUG
printf("[FURI] write: handler closed\n");
#endif
return false;
}
if(handler->record->value != NULL && size > handler->record->size) return false;
if(handler->record->value != NULL && size > handler->record->size) {
#ifdef FURI_DEBUG
printf("[FURI] write: wrong size %d\n", (uint32_t)size);
#endif
return false;
}
// check mute
if(
handler->record->mute_counter != handler->subscriber->mute_counter
&& !handler->subscriber->no_mute
) return false;
handler->record->mute_counter != handler->mute_counter
&& !handler->no_mute
) {
#ifdef FURI_DEBUG
printf("[FURI] write: muted\n");
#endif
return false;
}
if(handler->record->value != NULL) {
// real write to value