 942bbfaefe
			
		
	
	
		942bbfaefe
		
			
		
	
	
	
	
		
			
			* add input debounce code from old fw * exampl of input api * change input API to get/release * revert input API to read * pointer instead of instance * add input API description * add display API * rewrite display names * migrate to valuemanager * add LED API * add closing brakets * add sound api * fix led api * basic api * rename API pages * change pubsub implementation * move FURI AC -> flapp, add valuemutex example, add valuemanager implementation * pubsub usage example * user led example * update example * simplify input * add composed display * add SPI/GPIO and CC1101 bus * change cc1101 api * spi api and devices * spi api and devices * move SPI to page, add GPIO * not block pin open * backlight API and more * add minunit tests * fix logging * ignore unexisting time service on embedded targets * fix warning, issue with printf * Deprecate furi_open and furi_close (#167) Rename existing furi_open and furi_close to deprecated version * add exitcode * migrate to printf * indicate test by leds * add testing description * rename furi.h * wip basic api * add valuemutex, pubsub, split files * add value expanders * value mutex realization and tests * valuemutex test added to makefile * do not build unimplemented files * fix build furmware target f2 * redesigned minunit tests to allow testing in separate files * test file for valuemutex minunit testing * minunit partial test valuemutex * local cmsis_os2 mutex bindings * implement furi open/create, tests * migrate concurrent_access to ValueMutex * add spi header * Lib: add mlib submodule. Co-authored-by: rusdacent <rusdacentx0x08@gmail.com> Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
		
			
				
	
	
		
			83 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include "flipper.h"
 | |
| 
 | |
| /*
 | |
| == PubSub ==
 | |
| 
 | |
| PubSub allows users to subscribe on notifies and notify subscribers.
 | |
| Notifier side can pass `void*` arg to subscriber callback,
 | |
| and also subscriber can set `void*` context pointer that pass into
 | |
| callback (you can see callback signature below).
 | |
| */
 | |
| 
 | |
| typedef void(PubSubCallback*)(void*, void*);
 | |
| 
 | |
| typedef struct {
 | |
|     PubSubCallback cb;
 | |
|     void* ctx;
 | |
| } PubSubItem;
 | |
| 
 | |
| typedef struct {
 | |
|     PubSub* self;
 | |
|     PubSubItem* item;
 | |
| } PubSubId;
 | |
| 
 | |
| typedef struct {
 | |
|     PubSubItem items[NUM_OF_CALLBACKS];
 | |
|     PubSubId ids[NUM_OF_CALLBACKS]; ///< permanent links to item
 | |
|     size_t count; ///< count of callbacks
 | |
| } PubSub;
 | |
| 
 | |
| /*
 | |
| To create PubSub you should create PubSub instance and call `init_pubsub`.
 | |
| */
 | |
| void init_pubsub(PubSub* pubsub);
 | |
| 
 | |
| /*
 | |
| Use `subscribe_pubsub` to register your callback.
 | |
| */
 | |
| PubSubId* subscribe_pubsub(PubSub* pubsub, PubSubCallback cb, void* ctx);
 | |
| 
 | |
| /*
 | |
| Use `unsubscribe_pubsub` to unregister callback.
 | |
| */
 | |
| void unsubscribe_pubsub(PubSubId* pubsub_id);
 | |
| 
 | |
| /*
 | |
| Use `notify_pubsub` to notify subscribers.
 | |
| */
 | |
| void notify_pubsub(PubSub* pubsub, void* arg);
 | |
| 
 | |
| /*
 | |
| 
 | |
| ```C
 | |
| // MANIFEST
 | |
| // name="test"
 | |
| // stack=128
 | |
| 
 | |
| void example_pubsub_handler(void* arg, void* ctx) {
 | |
|     printf("get %d from %s\n", *(uint32_t*)arg, (const char*)ctx);
 | |
| }
 | |
| 
 | |
| void pubsub_test() {
 | |
|     const char* app_name = "test app";
 | |
| 
 | |
|     PubSub example_pubsub;
 | |
|     init_pubsub(&example_pubsub);
 | |
| 
 | |
|     if(!subscribe_pubsub(&example_pubsub, example_pubsub_handler, (void*)app_name)) {
 | |
|         printf("critical error\n");
 | |
|         flapp_exit(NULL);
 | |
|     }
 | |
| 
 | |
|     uint32_t counter = 0;
 | |
|     while(1) {
 | |
|         notify_pubsub(&example_pubsub, (void*)&counter);
 | |
|         counter++;
 | |
| 
 | |
|         osDelay(100);
 | |
|     }
 | |
| }
 | |
| ```
 | |
| */ |