This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,350 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Default", | ||
"intelliSenseMode": "clang-x64", | ||
"includePath": ["${workspaceFolder}/flipper", "${workspaceFolder}/helpers"] | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"files.associations": { | ||
"stddef.h": "c", | ||
"stdint.h": "c", | ||
"gui.h": "c", | ||
"canvas_i.h": "c", | ||
"core_defines.h": "c", | ||
"stdio.h": "c", | ||
"stdlib.h": "c", | ||
"record.h": "c", | ||
"crash.h": "c" | ||
}, | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.autopep8" | ||
}, | ||
"python.formatting.provider": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
LIBS = flipper/ | ||
HELPERS = helpers/ | ||
APP = flippulator_app_copy/ | ||
SOURCES = $(shell find $(LIBS) -name "*.c") $(shell find $(HELPERS) -name "*.c") | ||
SRC_APP = $(shell find $(APP) -name "*.c") | ||
OBJECTS = ${subst .c,.o,$(SOURCES)} | ||
OUT_APP = out | ||
OUT_LIB_NAME = flipper | ||
OUT_LIB = lib$(OUT_LIB_NAME).a | ||
CC_PREFIX = gcc -c -Wall# -fPIC | ||
CC_PREFIX_FINAL = gcc -Wall -Wno-main | ||
#CC_PREFIX = clang -c | ||
|
||
all: $(OUT_APP) | ||
|
||
$(OUT_APP):# $(OUT_LIB)# | ||
$(CC_PREFIX_FINAL) -I$(LIBS) -I$(HELPERS) $(SRC_APP) $(SOURCES) -o $(OUT_APP) | ||
|
||
#$(OUT_LIB): $(OBJECTS) | ||
# ar rcs $(OUT_LIB) $(OBJECTS) | ||
|
||
#$(LIBS)%.o: $(LIBS)%.c | ||
# $(CC_PREFIX) -I$(LIBS) -I$(HELPERS) -g $< -o $@ | ||
#$(HELPERS)%.o: $(HELPERS)%.c | ||
# $(CC_PREFIX) -I$(HELPERS) -g $< -o $@ | ||
|
||
clean: | ||
rm -rf $(OBJECTS) $(OUT_APP) $(OUT_LIB) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# flippulator | ||
An emulator for the Flipper Zero | ||
An emulator for the Flipper Zero\ | ||
Based on [Flipper Zero Firmware](https://github.com/flipperdevices/flipperzero-firmware) | ||
|
||
## Requirements | ||
A linux system\ | ||
Packages `make`, `gcc` | ||
|
||
## Usage | ||
|
||
## Limitations | ||
* The main function cannot be called `main` | ||
* `furi.h` must be included |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// https://github.com/flipperdevices/flipperzero-firmware/blob/dev/furi/core/base.h | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef enum { | ||
FuriWaitForever = 0xFFFFFFFFU, | ||
} FuriWait; | ||
|
||
typedef enum { | ||
FuriFlagWaitAny = 0x00000000U, ///< Wait for any flag (default). | ||
FuriFlagWaitAll = 0x00000001U, ///< Wait for all flags. | ||
FuriFlagNoClear = 0x00000002U, ///< Do not clear flags which have been specified to wait for. | ||
|
||
FuriFlagError = 0x80000000U, ///< Error indicator. | ||
FuriFlagErrorUnknown = 0xFFFFFFFFU, ///< FuriStatusError (-1). | ||
FuriFlagErrorTimeout = 0xFFFFFFFEU, ///< FuriStatusErrorTimeout (-2). | ||
FuriFlagErrorResource = 0xFFFFFFFDU, ///< FuriStatusErrorResource (-3). | ||
FuriFlagErrorParameter = 0xFFFFFFFCU, ///< FuriStatusErrorParameter (-4). | ||
FuriFlagErrorISR = 0xFFFFFFFAU, ///< FuriStatusErrorISR (-6). | ||
} FuriFlag; | ||
|
||
typedef enum { | ||
FuriStatusOk = 0, ///< Operation completed successfully. | ||
FuriStatusError = | ||
-1, ///< Unspecified RTOS error: run-time error but no other error message fits. | ||
FuriStatusErrorTimeout = -2, ///< Operation not completed within the timeout period. | ||
FuriStatusErrorResource = -3, ///< Resource not available. | ||
FuriStatusErrorParameter = -4, ///< Parameter error. | ||
FuriStatusErrorNoMemory = | ||
-5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. | ||
FuriStatusErrorISR = | ||
-6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. | ||
FuriStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. | ||
} FuriStatus; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// https://github.com/flipperdevices/flipperzero-firmware/blob/dev/furi/core/core_defines.h | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define FURI_RETURNS_NONNULL __attribute__((returns_nonnull)) | ||
|
||
#ifndef MAX | ||
#define MAX(a, b) \ | ||
({ \ | ||
__typeof__(a) _a = (a); \ | ||
__typeof__(b) _b = (b); \ | ||
_a > _b ? _a : _b; \ | ||
}) | ||
#endif | ||
|
||
#ifndef MIN | ||
#define MIN(a, b) \ | ||
({ \ | ||
__typeof__(a) _a = (a); \ | ||
__typeof__(b) _b = (b); \ | ||
_a < _b ? _a : _b; \ | ||
}) | ||
#endif | ||
|
||
#ifndef ABS | ||
#define ABS(a) ({ (a) < 0 ? -(a) : (a); }) | ||
#endif | ||
|
||
#ifndef ROUND_UP_TO | ||
#define ROUND_UP_TO(a, b) \ | ||
({ \ | ||
__typeof__(a) _a = (a); \ | ||
__typeof__(b) _b = (b); \ | ||
_a / _b + !!(_a % _b); \ | ||
}) | ||
#endif | ||
|
||
#ifndef CLAMP | ||
#define CLAMP(x, upper, lower) (MIN(upper, MAX(x, lower))) | ||
#endif | ||
|
||
#ifndef COUNT_OF | ||
#define COUNT_OF(x) (sizeof(x) / sizeof(x[0])) | ||
#endif | ||
|
||
#ifndef FURI_SWAP | ||
#define FURI_SWAP(x, y) \ | ||
do { \ | ||
typeof(x) SWAP = x; \ | ||
x = y; \ | ||
y = SWAP; \ | ||
} while(0) | ||
#endif | ||
|
||
#ifndef PLACE_IN_SECTION | ||
#define PLACE_IN_SECTION(x) __attribute__((section(x))) | ||
#endif | ||
|
||
#ifndef ALIGN | ||
#define ALIGN(n) __attribute__((aligned(n))) | ||
#endif | ||
|
||
#ifndef __weak | ||
#define __weak __attribute__((weak)) | ||
#endif | ||
|
||
#ifndef UNUSED | ||
#define UNUSED(X) (void)(X) | ||
#endif | ||
|
||
#ifndef STRINGIFY | ||
#define STRINGIFY(x) #x | ||
#endif | ||
|
||
#ifndef TOSTRING | ||
#define TOSTRING(x) STRINGIFY(x) | ||
#endif | ||
|
||
#ifndef CONCATENATE | ||
#define CONCATENATE(a, b) CONCATENATE_(a, b) | ||
#define CONCATENATE_(a, b) a##b | ||
#endif | ||
|
||
#ifndef REVERSE_BYTES_U32 | ||
#define REVERSE_BYTES_U32(x) \ | ||
((((x)&0x000000FF) << 24) | (((x)&0x0000FF00) << 8) | (((x)&0x00FF0000) >> 8) | \ | ||
(((x)&0xFF000000) >> 24)) | ||
#endif | ||
|
||
#ifndef FURI_BIT | ||
#define FURI_BIT(x, n) (((x) >> (n)) & 1) | ||
#endif | ||
|
||
#ifndef FURI_BIT_SET | ||
#define FURI_BIT_SET(x, n) \ | ||
({ \ | ||
__typeof__(x) _x = (1); \ | ||
(x) |= (_x << (n)); \ | ||
}) | ||
#endif | ||
|
||
#ifndef FURI_BIT_CLEAR | ||
#define FURI_BIT_CLEAR(x, n) \ | ||
({ \ | ||
__typeof__(x) _x = (1); \ | ||
(x) &= ~(_x << (n)); \ | ||
}) | ||
#endif | ||
|
||
#define FURI_SW_MEMBARRIER() asm volatile("" : : : "memory") | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "message_queue.h" | ||
#include "core_defines.h" | ||
|
||
FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size) { | ||
FuriMessageQueue* queue = (FuriMessageQueue*) malloc(12 + msg_count * msg_size); | ||
((uint32_t*) queue)[0] = 0; | ||
((uint32_t*) queue)[1] = msg_count; | ||
((uint32_t*) queue)[2] = msg_size; | ||
return queue; | ||
// 4 bytes for pointer | ||
// 4 bytes for count | ||
// 4 bytes for size | ||
// Other bytes for messages | ||
} | ||
|
||
void furi_message_queue_free(FuriMessageQueue* queue) { | ||
free(queue); | ||
} | ||
|
||
FuriStatus furi_message_queue_put(FuriMessageQueue* queue, const void* msg_ptr, uint32_t timeout) { | ||
UNUSED(timeout); | ||
const uint32_t pointer = ((uint32_t*) queue)[0]; | ||
const uint32_t count = ((uint32_t*) queue)[1]; | ||
const uint32_t size = ((uint32_t*) queue)[2]; | ||
if(pointer == count) return FuriStatusError; | ||
memcpy(queue + 12 + size * pointer, msg_ptr, size); | ||
((uint32_t*) queue)[0] += 1; | ||
return FuriStatusOk; | ||
} | ||
|
||
FuriStatus furi_message_queue_get(FuriMessageQueue* queue, void* msg_ptr, uint32_t timeout) { | ||
UNUSED(timeout); | ||
const uint32_t pointer = ((uint32_t*) queue)[0]; | ||
const uint32_t size = ((uint32_t*) queue)[2]; | ||
if(pointer == 0) return FuriStatusError; | ||
memcpy(msg_ptr, queue + 12, size); | ||
memcpy(queue + 12, queue + 12 + size, size * pointer); | ||
((uint32_t*) queue)[0] -= 1; | ||
return FuriStatusOk; | ||
} | ||
|
||
uint32_t furi_message_queue_get_capacity(FuriMessageQueue* queue) { | ||
return ((uint32_t*) queue)[1]; | ||
} | ||
|
||
uint32_t furi_message_queue_get_message_size(FuriMessageQueue* queue) { | ||
return ((uint32_t*) queue)[2]; | ||
} | ||
|
||
uint32_t furi_message_queue_get_count(FuriMessageQueue* queue) { | ||
return ((uint32_t*) queue)[0]; | ||
} | ||
|
||
uint32_t furi_message_queue_get_space(FuriMessageQueue* queue) { | ||
return furi_message_queue_get_capacity(queue) - furi_message_queue_get_count(queue); | ||
} | ||
|
||
FuriStatus furi_message_queue_reset(FuriMessageQueue* queue) { | ||
((uint32_t*) queue)[0] = 0; | ||
return FuriStatusOk; | ||
} |
Oops, something went wrong.