repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
zap
github_2023
zigzap
c
fio_tls_trust
int FIO_TLS_WEAK fio_tls_trust(fio_tls_s *tls, const char *public_cert_file) { REQUIRE_LIBRARY(); trust_s c = { .pem = FIO_STR_INIT, }; if (!public_cert_file) return 0; if (fio_str_readfile(&c.pem, public_cert_file, 0, 0).data == NULL) goto file_missing; trust_ary_push(&tls->trust, c); fio_t...
/** * Adds a certificate to the "trust" list, which automatically adds a peer * verification requirement. * * fio_tls_trust(tls, "google-ca.pem" ); */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L944-L960
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_accept
void FIO_TLS_WEAK fio_tls_accept(intptr_t uuid, fio_tls_s *tls, void *udata) { REQUIRE_LIBRARY(); fio_tls_attach2uuid(uuid, tls, udata, 1); }
/** * Establishes an SSL/TLS connection as an SSL/TLS Server, using the specified * context / settings object. * * The `uuid` should be a socket UUID that is already connected to a peer * (i.e., the result of `fio_accept`). * * The `udata` is an opaque user data pointer that is passed along to the * protocol se...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L972-L975
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_connect
void FIO_TLS_WEAK fio_tls_connect(intptr_t uuid, fio_tls_s *tls, void *udata) { REQUIRE_LIBRARY(); fio_tls_attach2uuid(uuid, tls, udata, 0); }
/** * Establishes an SSL/TLS connection as an SSL/TLS Client, using the specified * context / settings object. * * The `uuid` should be a socket UUID that is already connected to a peer * (i.e., one received by a `fio_connect` specified callback `on_connect`). * * The `udata` is an opaque user data pointer that ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L987-L990
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_dup
void FIO_TLS_WEAK fio_tls_dup(fio_tls_s *tls) { fio_atomic_add(&tls->ref, 1); }
/** * Increase the reference count for the TLS object. * * Decrease with `fio_tls_destroy`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L997-L997
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_destroy
void FIO_TLS_WEAK fio_tls_destroy(fio_tls_s *tls) { if (!tls) return; REQUIRE_LIBRARY(); if (fio_atomic_sub(&tls->ref, 1)) return; fio_tls_destroy_context(tls); alpn_list_free(&tls->alpn); cert_ary_free(&tls->sni); trust_ary_free(&tls->trust); free(tls); }
/** * Destroys the SSL/TLS context / settings object and frees any related * resources / memory. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/tls/fio_tls_openssl.c#L1003-L1014
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
initialize_cli
static void initialize_cli(int argc, char const *argv[]) { fio_cli_start( argc, argv, 0, 0, "This is a Hash algorythm collision test program. It accepts the " "following arguments:", FIO_CLI_STRING( "-test -t test only the specified algorithm. Options include:"), FIO_CLI_PRINT(...
/* ***************************************************************************** CLI ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/collisions.c#L97-L116
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
cleanup
static void cleanup(void) { print_flag = 0; hash_name_free(&hash_names); words_free(&words); }
/* ***************************************************************************** Cleanup ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/collisions.c#L174-L178
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
siphash13
static uintptr_t siphash13(char *data, size_t len) { return fio_siphash13(data, len, 0, 0); }
/* ***************************************************************************** Hash functions ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/collisions.c#L184-L186
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
inverse64_test
static uint64_t inverse64_test(uint64_t n, uint64_t inv) { uint64_t result = inv * (2 - (n * inv)); return result; }
/* ***************************************************************************** Finsing a mod64 inverse See: https://lemire.me/blog/2017/09/18/computing-the-inverse-of-odd-integers/ ***************************************************************************** */ /* will return `inv` if `inv` is inverse of `n` */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/collisions.c#L393-L396
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
attack_xxhash2
FIO_FUNC void attack_xxhash2(void) { /* POC - forcing XXHash to return seed only data (here, seed = 0) */ const uint64_t PRIME64_1 = 11400714785074694791ULL; const uint64_t PRIME64_2 = 14029467366897019727ULL; // const uint64_t PRIME64_3 = 1609587929392839161ULL; // const uint64_t PRIME64_4 = 9650029242287828...
/* ***************************************************************************** Hash Breaking Word Workshop ***************************************************************************** */ /** * Attacking 8 byte words, which follow this code path: * h64 = seed + PRIME64_5; * h64 += len; // len == 8 * ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/collisions.c#L446-L486
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
add_bad4xxhash
FIO_FUNC void add_bad4xxhash(void) { attack_xxhash(); const uint64_t PRIME64_1 = 11400714785074694791ULL; const uint64_t PRIME64_2 = 14029467366897019727ULL; const uint64_t PRIME64_1_INV = inverse64(PRIME64_1); const uint64_t PRIME64_2_INV = inverse64(PRIME64_2); const uint64_t seed_manipulation[4] = {PRIME...
/** * Attacking 64 byte messages where the last 32 bytes are the same and the first * 32 bytes use rotating 8 byte words. This is attcking the following part in * the code: * * U64 v1 = seed + PRIME64_1 + PRIME64_2; * U64 v2 = seed + PRIME64_2; * U64 v3 = seed + 0; * U64 v4 = seed - PRIME64_1; * *...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/collisions.c#L574-L640
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_risky_hash2
static inline uintptr_t fio_risky_hash2(const void *data_, size_t len, uint64_t seed) { /* The primes used by Risky Hash */ const uint64_t primes[] = { 0xFBBA3FA15B22113B, // 1111101110111010001111111010000101011011001000100001000100111011 0xAB137439982B86C9, // 1...
/* Computes a facil.io Risky Hash. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/collisions.c#L692-L781
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
seek3
static inline int seek3(uint8_t **buffer, register uint8_t *const limit, const uint8_t c) { if (**buffer == c) return 1; #if !__x86_64__ && !__aarch64__ /* too short for this mess */ if ((uintptr_t)limit <= 16 + ((uintptr_t)*buffer & (~(uintptr_t)7))) goto finish; /* align memo...
/** * This seems to be faster on some systems, especially for smaller distances. * * On newer systems, `memchr` should be faster. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/memchr_speed.c#L38-L83
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
pco_scale
static double pco_scale(double x, double n) { if (x >= 1.0 || x <= 0.0) return x; /* This is the result we want: return 1.0 - pow(1.0 - x, n); except the important cases are with x very small so this method gives better accuracy. */ return -expm1(log1p(-x) * n); }
/* Probability that the smallest of n numbers in [0..1) is <= x . */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L248-L257
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
get_count
static inline int get_count(uint32_t cs) { return cs >> SUM_BITS; }
/* The idea of the test is based around Hamming weights. We calculate the average number of bits per BITS-bit word and how it depends on the weights of the previous DIM words. There are SIZE different categories for the previous words. For each one accumulate number of samples (get_count(cs[j]) and count_su...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L271-L271
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
update_cs
static inline void update_cs(int bc, uint32_t *p) { *p += bc + (1 << SUM_BITS); }
/* We add bc to the sum field of *p then add 1 to the count field. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L276-L278
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
desat
static void desat(const int64_t next_batch_size) { int64_t c = 0, s = 0; for (int i = 0; i < SIZE; i++) { const int32_t st = cs[i]; const int count = get_count(st); const int sum = get_sum(st); c += count; s += sum; count_sum[i].c += count; /* In cs[] the total Hamming weight is stor...
/* Copy accumulated numbers out of cs[] into count_sum, then zero the ones in cs[]. We have to check explicitly that values do not overflow. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L310-L335
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
desat
static void desat(const int64_t next_batch_size) { int64_t c = 0; for (uint64_t i = 0; i < SIZE; i++) { const int32_t st = cs[i]; const int count = get_count(st); c += count; count_sum[i].c += count; /* In cs[] the total Hamming weight is stored as actual weight. In count_sum, it is st...
/* Copy accumulated numbers out of cs[] into count_sum, then zero the ones in cs[]. Note it is impossible for totals to overflow unless counts do. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L342-L364
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
print_sig
static void print_sig(uint32_t sig) { for (uint64_t i = DIM; i > 0; i--) { putchar(sig % 3 + '0'); sig /= 3; } }
/* Now we're out of the the accumulate phase, which is the inside loop. Next is analysis. */ /* Mostly a debugging printf, though it can tell you a bit about the structure of a prng when it fails. Print sig out in base 3, least significant digits first. This means the most recent trit is the rightmost. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L488-L493
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
mix3
static void mix3(double *ct, int sig) { double *p1 = ct + sig, *p2 = p1 + sig; double a, b, c; for (int i = 0; i < sig; i++) { a = ct[i]; b = p1[i]; c = p2[i]; ct[i] = (a + b + c) * CORRECT3; p1[i] = (a - c) * M_SQRT1_2; p2[i] = (2 * b - a - c) * CORRECT6; } sig = DIV3(sig); if (si...
/* This is a transform similar in spirit to the Walsh-Hadamard transform (see the paper). It's ortho-normal. So with independent normal distribution mean 0 standard deviation 1 in, we get independent normal distribution mean 0 standard deviation 1 out, except maybe for element 0. And of course, for certain kind...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L511-L530
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
cat
static int cat(uint32_t sig) { int r = 0; while (sig) { r += (sig % 3) != 0; sig /= 3; } return (r >= NUMCATS ? NUMCATS : r) - 1; }
/* categorise sig based on nonzero ternary digits. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L533-L542
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
analyze
static void analyze(int64_t pos, bool trans, bool final) { if (pos < 2 * pow(2.0 / (1.0 - P), DIM)) printf("WARNING: p-values are unreliable, you have to wait (insufficient " "data for meaningful answer)\n"); const double pvalue = compute_pvalue(trans); const time_t tm = time(0); printf("proce...
/* This is the call made when we want to print some analysis. This will be done multiple times if --progress is used. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/random.c#L623-L645
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
prep_msg
static void prep_msg(void) { ASSERT_COND(strlen(address) < 512, "host name too long"); if (USE_PIPELINING) { MSG_LEN = strlen(HTTP_REQUEST_HEAD) + strlen(address) + 4; REQ_PER_MSG = 1; memcpy(MSG_OUTPUT, HTTP_REQUEST_HEAD, strlen(HTTP_REQUEST_HEAD)); memcpy(MSG_OUTPUT + strlen(HTTP_REQUEST_HEAD), ad...
/* copies an HTTP request to the internal buffer */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L92-L119
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
sig_int_handler
static void sig_int_handler(int sig) { signal(SIGINT, SIG_DFL); switch (sig) { case SIGINT: /* fallthrough */ case SIGTERM: /* fallthrough */ flag = 0; break; default: break; } }
/* handles the SIGUSR1, SIGINT and SIGTERM signals. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L122-L132
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
main
int main(int argc, char const *argv[]) { int result = 0; ASSERT_COND(argc == 3 || argc == 4, "\nTo test HTTP/1.1 server against Slowloris, " "use: %s addr port [attackers]\ni.e.:\n\t\t%s example.com 80" "\n\t\t%s localhost 3000 24", argv[0], argv[0], argv[0]);...
/* ***************************************************************************** Main attack function ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L163-L264
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
set_non_block
static int set_non_block(int fd) { /* If they have O_NONBLOCK, use the Posix way to do it */ #if defined(O_NONBLOCK) /* Fixme: O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */ int flags; if (-1 == (flags = fcntl(fd, F_GETFL, 0))) flags = 0; // printf("flags initial value was %d\n", flags); ...
/* ***************************************************************************** IO Helpers ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L290-L306
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
connect2tcp
static int __attribute__((unused)) connect2tcp(const char *a, const char *p) { /* TCP/IP socket */ struct addrinfo hints = {0}; struct addrinfo *addrinfo; // will point to the results memset(&hints, 0, sizeof hints); // make sure the struct is empty hints.ai_family = AF_UNSPEC; // don't care IPv4 or...
/** Opens a TCP/IP connection using a blocking IO socket */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L309-L343
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
wait__internal
static inline int wait__internal(int fd, uint16_t events) { errno = 0; int i = 0; if (fd == -1) goto badfd; struct pollfd ls = {.fd = fd, .events = events}; i = poll(&ls, 1, 1000); if (i > 0) { if ((ls.revents & POLLHUP) || (ls.revents & POLLERR) || (ls.revents & POLLNVAL)) goto badfd;...
/* ***************************************************************************** Polling Helpers ***************************************************************************** */ /** Waits for socket to become available for either reading or writing */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L350-L374
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
wait4fd
static __attribute__((unused)) int wait4fd(int fd) { return wait__internal(fd, POLLIN | POLLOUT); }
/** Waits for socket to become available for either reading or writing */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L377-L379
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
wait4read
static __attribute__((unused)) int wait4read(int fd) { return wait__internal(fd, POLLIN); }
/** Waits for socket to become available for reading */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L381-L383
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
wait4write
static __attribute__((unused)) int wait4write(int fd) { return wait__internal(fd, POLLOUT); }
/** Waits for socket to become available for reading */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L385-L387
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
test_server
static test_err_en test_server(size_t timeout) { int fd = connect2tcp(address, port); if (fd == -1) { if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) return OPENFILE_LIMIT; return CONNECTION_FAILED; } time_t start = 0; time(&start); size_t blocks = 0; while (wait4write(fd) < 0)...
/* ***************************************************************************** Test ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L393-L451
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
attack_server
static void attack_server(void) { int fd = connect2tcp(address, port); size_t offset = 0; uint8_t read_once = 0; while (flag) { if (wait4write(fd) == 0) { ssize_t w = write(fd, MSG_OUTPUT + offset, MSG_LEN - offset); if (w < 0) { /* error... waiting? */ if (errno != EWOULDBLOCK &...
/* ***************************************************************************** Attack ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/tests/slowloris.c#L457-L505
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
flipper-zero-tutorials
github_2023
jamisonderek
c
i2c_find_device
static uint8_t i2c_find_device() { uint8_t addr = 0; furi_hal_i2c_acquire(i2c_bus); for(uint8_t try_addr = 0x20; try_addr != 0xff; try_addr++) { if(furi_hal_i2c_is_device_ready(i2c_bus, try_addr, 10)) { addr = try_addr; FURI_LOG_D(TAG, "Found device at %02x", addr); ...
/** * @brief Find an I2C device on the external bus. * @details This function scans the external I2C bus to find a device. * Ideally only a MCP4725 would be connected. It returns the first address of any device found. * @return The address of the device, or 0 if not found. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L75-L90
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
i2c_set_voltage
static void i2c_set_voltage(VoltageModel* voltage_model, uint16_t amount) { furi_assert(voltage_model != NULL); if(amount > 4095) { amount = 4095; } uint32_t timeout = 100; uint8_t buffer[3] = {0x0}; // We use the 3-bytes to transfer data. // There is also a 2-byte transfer which s...
/** * @brief Set the voltage on the MCP4725. * @details This function sets the voltage on the MCP4725. It writes the value to the DAC register. * @param voltage_model The voltage model object. * @param amount The amount to set the voltage register to (0 to 4095). */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L98-L144
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
navigation_exit_callback
static uint32_t navigation_exit_callback(void* _context) { UNUSED(_context); return VIEW_NONE; }
/** * @brief Callback for exiting the application. * @details Return VIEW_NONE to indicate that we want to exit the application. * @param _context The context - unused * @return next view id (VIEW_NONE) */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L152-L155
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
navigation_submenu_callback
static uint32_t navigation_submenu_callback(void* _context) { UNUSED(_context); return DacViewSubmenu; }
/** * @brief Callback for returning to submenu. * @details This function is called when user press back button. We return DacViewSubmenu to * indicate that we want to navigate to the submenu. * @param _context The context - unused * @return next view id (DacViewSubmenu) */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L164-L167
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
submenu_selection_callback
static void submenu_selection_callback(void* context, uint32_t index) { DacApp* app = (DacApp*)context; switch(index) { case DacSubmenuIndexVoltage: view_dispatcher_switch_to_view(app->view_dispatcher, DacViewVoltage); break; case DacSubmenuIndexAbout: view_dispatcher_switch_to_v...
/** * @brief Handle submenu item selection. * @details This function is called when user selects an item from the submenu. * @param context The context - DacApp object. * @param index The SubmenuIndex item that was clicked. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L175-L187
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
voltage_view_draw_callback
static void voltage_view_draw_callback(Canvas* canvas, void* model) { VoltageModel* my_model = (VoltageModel*)model; canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned(canvas, 10, 1, AlignLeft, AlignTop, "Voltage"); canvas_set_font(canvas, FontSecondary); FuriString* str = furi_string_a...
/** * @brief Callback for drawing the voltage screen. * @details This function is called when the screen needs to be redrawn, like when the model gets updated. * @param canvas The canvas to draw on. * @param model The model - MyModel object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L195-L224
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
dac_timer_callback
static void dac_timer_callback(void* context) { DacApp* app = (DacApp*)context; view_dispatcher_send_custom_event(app->view_dispatcher, DacEventIdSampleAdc); }
/** * @brief Callback for timer elapsed. * @details This function is called when the timer is elapsed. We use this to queue a redraw event. * @param context The context - DacApp object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L231-L234
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
voltage_view_enter_callback
static void voltage_view_enter_callback(void* context) { uint32_t period = furi_ms_to_ticks(200); DacApp* app = (DacApp*)context; furi_assert(app->timer == NULL); app->timer = furi_timer_alloc(dac_timer_callback, FuriTimerTypePeriodic, context); furi_timer_start(app->timer, period); view_dispatc...
/** * @brief Callback when the user starts the voltage screen. * @details This function is called when the user enters the voltage screen. We start a timer to * redraw the screen periodically (so the random number is refreshed). * @param context The context - DacApp object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L242-L250
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
voltage_view_exit_callback
static void voltage_view_exit_callback(void* context) { DacApp* app = (DacApp*)context; furi_timer_stop(app->timer); furi_timer_free(app->timer); app->timer = NULL; }
/** * @brief Callback when the user exits the voltage screen. * @details This function is called when the user exits the voltage screen. We stop the timer. * @param context The context - DacApp object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L257-L262
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
voltage_view_custom_event_callback
static bool voltage_view_custom_event_callback(uint32_t event, void* context) { DacApp* app = (DacApp*)context; bool redraw = false; switch(event) { case DacEventIdSampleAdc: // Read a new ADC voltage value. { redraw = true; with_view_model( app->...
/** * @brief Callback for custom events. * @details This function is called when a custom event is sent to the view dispatcher. * @param event The event id - DacEventId value. * @param context The context - DacApp object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L270-L309
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
voltage_view_input_callback
static bool voltage_view_input_callback(InputEvent* event, void* context) { DacApp* app = (DacApp*)context; if(event->type == InputTypeShort) { bool redraw = true; if(event->key == InputKeyLeft) { // Left button clicked, reduce x coordinate. with_view_model( ...
/** * @brief Callback for voltage screen input. * @details This function is called when the user presses a button while on the voltage screen. * @param event The event - InputEvent object. * @param context The context - DacApp object. * @return true if the event was handled, false otherwi...
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L318-L449
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
dac_app_free
static void dac_app_free(DacApp* app) { with_view_model( app->view_voltage, VoltageModel * model, { furi_hal_adc_release(model->adc_handle); }, false); furi_hal_pwm_stop(channel_pwm); view_dispatcher_remove_view(app->view_dispatcher, DacViewAbout); widget_free(app->widge...
/** * @brief Free the dac application. * @details This function frees the dac application resources. * @param app The dac application object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L554-L572
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
attempt_enable_5v
static bool attempt_enable_5v() { bool enabled_5v = false; if(furi_hal_power_is_otg_enabled() || furi_hal_power_is_charging()) { enabled_5v = false; } else { // Some other apps make multiple attempts, so we retry too. uint8_t attempts = 5; while(--attempts > 0) { ...
/** * @brief Attempt to enable +5 Volt GPIO pin #1. * @details This function attempts to enable 5V power. It will return true if not already enabled and it was successful. * @return true if 5V was enabled, false otherwise. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L579-L594
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
analog_output_app
int32_t analog_output_app(void* _p) { UNUSED(_p); DacApp* app = dac_app_alloc(); bool app_enabled_5v = attempt_enable_5v(); view_dispatcher_run(app->view_dispatcher); dac_app_free(app); if(app_enabled_5v) { furi_hal_power_disable_otg(); } return 0; }
/** * @brief Main function for application. * @details This function is the entry point for the application. It should be defined in * application.fam as the entry_point setting. * @param _p Input parameter - unused * @return 0 - Success */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/dac/app.c#L603-L613
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_7segment_input_callback
static void gpio_7segment_input_callback(InputEvent* input_event, FuriMessageQueue* queue) { furi_assert(queue); GpioEvent event = {.type = GpioEventTypeKey, .input = *input_event}; furi_message_queue_put(queue, &event, FuriWaitForever); }
// Invoked when input (button press) is detected. Queues message and returns to caller. // @param input_event the input event that caused the callback to be invoked. // @param queue the message queue for queueing key event.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_7segment/gpio_7segment_app.c#L104-L108
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_7segment_render_callback
static void gpio_7segment_render_callback(Canvas* canvas, void* ctx) { // Attempt to aquire context, so we can read the data. GpioContext* context = ctx; if(furi_mutex_acquire(context->mutex, 200) != FuriStatusOk) { return; } GpioData* data = context->data; // Title canvas_set_font...
// Invoked by the draw callback to render the screen. // @param canvas surface to draw on. // @param ctx a pointer to the application GpioContext.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_7segment/gpio_7segment_app.c#L113-L149
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_7segment_show
void gpio_7segment_show(int digit, bool invert) { // There are 7 segments per digit. int index = 7 * digit; furi_hal_gpio_write(&gpio_ext_pa7, digits[index++] ^ invert); furi_hal_gpio_write(&gpio_ext_pa6, digits[index++] ^ invert); furi_hal_gpio_write(&gpio_ext_pa4, digits[index++] ^ invert); f...
// Sets the GPIO pin output to display a number. // @param digit a value between 0-9 to display. // @param invert use true if your 7-segment LED display is common anode // (and all the output pins go to cathode side of LEDs). use false if // your display is common cathode.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_7segment/gpio_7segment_app.c#L156-L167
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_7segment_disconnect_pin
void gpio_7segment_disconnect_pin(const GpioPin* pin) { furi_hal_gpio_init(pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow); furi_hal_gpio_write(pin, true); }
// Disconnects a GpioPin via OutputOpenDrive, PushPullNo, output true. // @pin pointer to GpioPin to disconnect.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_7segment/gpio_7segment_app.c#L171-L174
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_7segment_app
int32_t gpio_7segment_app(void* p) { UNUSED(p); // Configure our initial data. GpioContext* context = malloc(sizeof(GpioContext)); context->mutex = furi_mutex_alloc(FuriMutexTypeNormal); context->data = malloc(sizeof(GpioData)); context->data->buffer = furi_string_alloc(); context->data->di...
// This is the entry point to our application.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_7segment/gpio_7segment_app.c#L177-L277
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
demo_input_callback
static void demo_input_callback(InputEvent* input_event, FuriMessageQueue* queue) { furi_assert(queue); DemoEvent event = {.type = DemoEventTypeKey, .input = *input_event}; furi_message_queue_put(queue, &event, FuriWaitForever); }
// The LED at the time of GPIO interrupt (or 0 if none). // Invoked when input (button press) is detected. // We queue a message and then return to the caller. // @input_event the button that triggered the callback. // @queue our message queue.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_interrupt_demo/gpio_interrupt_demo_app.c#L67-L71
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
demo_tick
static void demo_tick(void* ctx) { furi_assert(ctx); FuriMessageQueue* queue = ctx; DemoEvent event = {.type = DemoEventTypeTick}; furi_message_queue_put(queue, &event, 0); }
// Invoked from our timer. We queue a message and then return to the caller. // @ctx our message queue.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_interrupt_demo/gpio_interrupt_demo_app.c#L75-L80
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
demo_gpio_fall_callback
static void demo_gpio_fall_callback(void* ctx) { UNUSED(ctx); selectedLed = currentLed; }
// Invoked when our GPIO pin transitions from VCC to GND. // @ctx unused for this method.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_interrupt_demo/gpio_interrupt_demo_app.c#L84-L87
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
demo_render_callback
static void demo_render_callback(Canvas* canvas, void* ctx) { // Attempt to aquire context, so we can read the data. DemoContext* demo_context = ctx; if(furi_mutex_acquire(demo_context->mutex, 200) != FuriStatusOk) { return; } DemoData* data = demo_context->data; if(selectedLed) { ...
// Invoked by the draw callback to render the screen. // We render our UI on the callback thread. // @canvas the surface to render our UI // @ctx a pointer to a DemoContext object.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_interrupt_demo/gpio_interrupt_demo_app.c#L93-L113
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
update_led
void update_led(uint8_t led) { if(led == 1 || led == 3) { // Pin A7 is 3.3 volts for LED 1 & 3. furi_hal_gpio_init(&gpio_ext_pa7, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow); furi_hal_gpio_write(&gpio_ext_pa7, true); } else { furi_hal_gpio_init(&gpio_ext_pa7, GpioModeOutput...
// Turns on one of the LEDs. // @pin the LED to turn on (value of 1-6)
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_interrupt_demo/gpio_interrupt_demo_app.c#L117-L147
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
disconnect_pin
void disconnect_pin(const GpioPin* pin) { furi_hal_gpio_init(pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow); furi_hal_gpio_write(pin, true); }
// Disconnects a GpioPin via OutputOpenDrive, PushPullNo, output true. // @pin pointer to GpioPin to disconnect.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_interrupt_demo/gpio_interrupt_demo_app.c#L151-L154
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_interrupt_demo_app
int32_t gpio_interrupt_demo_app(void* p) { UNUSED(p); // Configure our initial data. DemoContext* demo_context = malloc(sizeof(DemoContext)); demo_context->mutex = furi_mutex_alloc(FuriMutexTypeNormal); demo_context->data = malloc(sizeof(DemoData)); demo_context->data->buffer = furi_string_allo...
// Program entry point
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_interrupt_demo/gpio_interrupt_demo_app.c#L157-L260
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_polling_demo_input_callback
static void gpio_polling_demo_input_callback(InputEvent* input_event, FuriMessageQueue* queue) { furi_assert(queue); DemoEvent event = {.type = DemoEventTypeKey, .input = *input_event}; furi_message_queue_put(queue, &event, FuriWaitForever); }
// This is the pin used for our GPIO demo. // Invoked when input (button press) is detected. We queue a message and then return to the caller.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_polling_demo/gpio_polling_demo_app.c#L46-L50
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_polling_demo_tick
static void gpio_polling_demo_tick(void* ctx) { furi_assert(ctx); FuriMessageQueue* queue = ctx; DemoEvent event = {.type = DemoEventTypeTick}; // It's OK to loose this event if system overloaded (so we don't pass a wait value for 3rd parameter.) furi_message_queue_put(queue, &event, 0); }
// Invoked by the timer on every tick. We queue a message and then return to the caller.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_polling_demo/gpio_polling_demo_app.c#L53-L59
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_polling_demo_render_callback
static void gpio_polling_demo_render_callback(Canvas* canvas, void* ctx) { // Attempt to aquire context, so we can read the data. DemoContext* demo_context = ctx; if(furi_mutex_acquire(demo_context->mutex, 200) != FuriStatusOk) { return; } DemoData* data = demo_context->data; bool show_...
// Invoked by the draw callback to render the screen. We render our UI on the callback thread.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_polling_demo/gpio_polling_demo_app.c#L62-L97
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
gpio_polling_demo_update_pin_status
static void gpio_polling_demo_update_pin_status(void* ctx) { DemoContext* demo_context = ctx; DemoData* data = demo_context->data; data->counter++; // read returns true for VCC and false for ground, so invert answer. data->pin_grounded = !furi_hal_gpio_read(&demo_message_pin); }
// Our main loop invokes this method after acquiring the mutex, so we can safely access the protected data. // We increment a counter and update if the GPIO pin is grounded.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/gpio_polling_demo/gpio_polling_demo_app.c#L101-L108
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
input_callback
static void input_callback(InputEvent* input_event, FuriMessageQueue* queue) { furi_assert(queue); DemoEvent event = {.type = DemoEventTypeKey, .input = *input_event}; furi_message_queue_put(queue, &event, FuriWaitForever); }
// Invoked when input (button press) is detected. We queue a message and then return to the caller.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/i2c_demo/i2c_demo_app.c#L57-L61
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
tick_callback
static void tick_callback(void* ctx) { furi_assert(ctx); FuriMessageQueue* queue = ctx; DemoEvent event = {.type = DemoEventTypeTick}; // It's OK to loose this event if system overloaded (so we don't pass a wait value for 3rd parameter.) furi_message_queue_put(queue, &event, 0); }
// Invoked by the timer on every tick. We queue a message and then return to the caller.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/i2c_demo/i2c_demo_app.c#L64-L70
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
render_callback
static void render_callback(Canvas* canvas, void* ctx) { // Attempt to aquire context, so we can read the data. DemoContext* demo_context = ctx; if(furi_mutex_acquire(demo_context->mutex, 200) != FuriStatusOk) { return; } DemoData* data = demo_context->data; canvas_set_font(canvas, Fon...
// Invoked by the draw callback to render the screen. We render our UI on the callback thread.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/i2c_demo/i2c_demo_app.c#L73-L110
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
update_i2c_status
static void update_i2c_status(void* ctx) { DemoContext* demo_context = ctx; DemoData* data = demo_context->data; uint8_t addr = 0; addr = demo_i2c_find_device(); if(addr) { data->state = I2cDemoStateFound; if(demo_i2c_init_bh1750(addr)) { data->state = I2cDemoStateWrit...
// Our main loop invokes this method after acquiring the mutex, so we can safely access the protected data.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/i2c_demo/i2c_demo_app.c#L226-L254
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
input_callback
static void input_callback(InputEvent* input_event, FuriMessageQueue* queue) { furi_assert(queue); DemoEvent event = {.type = DemoEventTypeKey, .input = *input_event}; furi_message_queue_put(queue, &event, FuriWaitForever); }
// Invoked when input (button press) is detected. // We queue a message and then return to the caller. // @input_event the button that triggered the callback. // @queue our message queue.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/memsic_2125/memsic_2125_app.c#L65-L69
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
pulse_callback
void pulse_callback(void* data) { // Get the current time from high-resolution timer. FuriHalCortexTimer timer = furi_hal_cortex_timer_get(0); uint32_t now = timer.start; // Our parameter is a pointer to the axis data. furi_assert(data); AxisData* d = (AxisData*)data; // Get the current st...
// Invoked whenever the monitored pin changes state. // @data pointer to an AxisData.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/memsic_2125/memsic_2125_app.c#L73-L103
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
render_callback
static void render_callback(Canvas* canvas, void* ctx) { // Attempt to aquire context, so we can read the data. DemoContext* demo_context = ctx; DemoData* data = demo_context->data; canvas_set_font(canvas, FontPrimary); canvas_draw_str_aligned(canvas, 1, 1, AlignLeft, AlignTop, "Memsic 2125 C1:X C...
// Invoked by the draw callback to render the screen. // We render our UI on the callback thread. // @canvas the surface to render our UI // @ctx a pointer to a DemoContext object.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/memsic_2125/memsic_2125_app.c#L109-L136
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
memsic_2125_app
int32_t memsic_2125_app(void* p) { UNUSED(p); // Configure our initial data. DemoContext* demo_context = malloc(sizeof(DemoContext)); demo_context->data = malloc(sizeof(DemoData)); demo_context->data->buffer = furi_string_alloc(); AxisData* xData = malloc(sizeof(AxisData)); xData->pin = &g...
// Program entry point
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/memsic_2125/memsic_2125_app.c#L139-L226
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
uart_demo_submenu_add_default_entries
static void uart_demo_submenu_add_default_entries(Submenu* submenu, void* context) { UartDemoApp* app = context; submenu_reset(submenu); submenu_add_item(submenu, "Clear", 0, uart_demo_submenu_item_callback, context); submenu_add_item(submenu, "Send Msg 1", 1, uart_demo_submenu_item_callback, context); ...
/** * Adds the default submenu entries. * * @param submenu The submenu. * @param context The context to pass to the submenu item callback function. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/uart_demo/uart_demo.c#L49-L57
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
uart_helper_received_byte_callback
static void uart_helper_received_byte_callback( FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) { UartHelper* helper = context; if(event == FuriHalSerialRxEventData) { uint8_t data = furi_hal_serial_async_rx(handle); furi_stream_buffer_send(helper->rx_stream,...
/** * Invoked when a byte of data is received on the UART bus. This function * adds the byte to the stream buffer and sets the WorkerEventDataWaiting flag. * * @param handle Serial handle * @param event FuriHalSerialRxEvent * @param context UartHelper instance */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/uart_demo/uart_helper.c#L60-L71
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
uart_helper_worker
static int32_t uart_helper_worker(void* context) { UartHelper* helper = context; FuriString* line = furi_string_alloc(); uint32_t events; do { events = furi_thread_flags_wait( WorkerEventDataWaiting | WorkerEventExiting, FuriFlagWaitAny, FuriWaitForever); if(events & Worker...
/** * Worker thread that dequeues data from the stream buffer and processes it. When * a delimiter is found in the data, the line is extracted and the process_line callback * is invoked. This thread will exit when the WorkerEventExiting flag is set. * * @param context UartHelper instance * @return 0 *...
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/uart_demo/uart_helper.c#L81-L160
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
wiegand_menu_callback
void wiegand_menu_callback(void* context, uint32_t index) { App* app = context; WiegandMainMenuEvent event = WiegandMainMenuUnknownEvent; switch(index) { case WiegandMainMenuInstructions: event = WiegandMainMenuInstructionsEvent; break; case WiegandMainMenuRead: event = Wiega...
/* Triggers a custom event that is handled in the main menu on_scene handler. @param context Pointer to the application context. @param index Index of the selected menu item to map to custom event. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/wiegand/scenes/wiegand_main_menu.c#L8-L29
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
wiegand_main_menu_scene_on_enter
void wiegand_main_menu_scene_on_enter(void* context) { App* app = context; submenu_reset(app->submenu); submenu_set_header(app->submenu, "Wiegand"); submenu_add_item( app->submenu, "Instructions", WiegandMainMenuInstructions, wiegand_menu_callback, app); submenu_add_item(app->submenu, "Read"...
/* Displays the main menu. @param context Pointer to the application context. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/wiegand/scenes/wiegand_main_menu.c#L35-L46
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_navigation_exit_callback
static uint32_t led_tester_navigation_exit_callback(void* _context) { UNUSED(_context); return VIEW_NONE; }
/** * @brief Callback for exiting the application. * @details This function is called when user press back button. We return VIEW_NONE to * indicate that we want to exit the application. * @param _context The context - unused * @return next view id */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L68-L71
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_navigation_submenu_callback
static uint32_t led_tester_navigation_submenu_callback(void* _context) { UNUSED(_context); return LedTesterViewSubmenu; }
/** * @brief Callback for the application's menu. * @details This function is called when user press back button. We return LedTesterViewSubmenu to * indicate that we want to return to the application menu. * @param _context The context - unused * @return next view id */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L80-L83
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_submenu_callback
static void led_tester_submenu_callback(void* context, uint32_t index) { LedTesterApp* app = (LedTesterApp*)context; switch(index) { case LedTesterSubmenuIndexLeds: view_dispatcher_switch_to_view(app->view_dispatcher, LedTesterViewLeds); break; case LedTesterSubmenuIndexAbout: vi...
/** * @brief Handle submenu item selection. * @details This function is called when user selects an item from the submenu. * @param context The context - LedTesterApp object. * @param index The LedTesterSubmenuIndex item that was clicked. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L91-L103
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_timer_callback
static void led_tester_timer_callback(void* context) { LedTesterApp* app = (LedTesterApp*)context; view_dispatcher_send_custom_event(app->view_dispatcher, LedTesterEventTimer); }
/** * @brief Callback for timer elapsed. * @details This function is called when the timer is elapsed. * @param context The context - LedTesterApp object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L110-L113
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_settings_updated
static void led_tester_settings_updated(LedTesterApp* app) { view_dispatcher_send_custom_event(app->view_dispatcher, LedTesterEventConfigChange); }
/** * @brief Callback for when the LED configuration settings are updated. * @details This function is called when the LED configuration settings are changed by the user. * @param context The context - LedTesterApp object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L120-L122
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_item_clicked
static void led_tester_item_clicked(void* context, uint32_t index) { UNUSED(index); LedTesterApp* app = (LedTesterApp*)context; view_dispatcher_send_custom_event(app->view_dispatcher, LedTesterEventClicked); }
/** * @brief Callback for when the LED configuration settings are clicked. * @details This function is called when the user presses OK button while in the LED configuration settings. * @param context The context - LedTesterApp object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L129-L133
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_5v_power_on
static void led_tester_5v_power_on() { uint8_t attempts = 5; while(--attempts > 0) { if(furi_hal_power_enable_otg()) break; } }
/** * @brief Enable 5V power. * @details This function enables the 5V power output on pin 1. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L139-L144
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_5v_power_off
static void led_tester_5v_power_off() { if(furi_hal_power_is_otg_enabled()) { furi_hal_power_disable_otg(); } }
/** * @brief Disable 5V power. * @details This function disables the 5V power output on pin 1. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L150-L154
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_setting_led_count_change
static void led_tester_setting_led_count_change(VariableItem* item) { LedTesterApp* app = variable_item_get_context(item); LedTesterModel* model = app->model; uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, setting_led_count_names[index]); mode...
// 4 LEDs
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L175-L182
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_custom_event_callback
static bool led_tester_custom_event_callback(void* context, uint32_t event) { LedTesterApp* app = (LedTesterApp*)context; const GpioPin* pin = setting_led_pin_values[app->model->led_pin_index]; if(!app->led_driver) { FURI_LOG_E(TAG, "led_driver is NULL. Custom event %lu ignored.", event); ...
/** * @brief Callback for custom events. * @details This function is called when a custom event is sent to the view dispatcher. * @param context The context - LedTesterApp object. * @param event The event id - LedTesterEventId value. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L247-L357
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_enter_leds_callback
void led_tester_enter_leds_callback(void* _context) { // _context is variable_item_list, but it doesn't expose the item, so we can't get the context. UNUSED(_context); // Hack, we use a global to access the app object. LedTesterApp* app = (LedTesterApp*)global_app; app->timer = furi_timer_alloc(led_...
/** * @brief Callback for entering the LED configuration settings. * @details This function is called when the user enters the LED configuration settings. We * start the periodic timer to update the LEDs & we signal initialized so the LEDs * turn on to their default state. * @pa...
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L366-L376
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_exit_leds_callback
void led_tester_exit_leds_callback(void* _context) { // _context is variable_item_list, but it doesn't expose the item, so we can't get the context. UNUSED(_context); // Hack, we use a global to access the app object. LedTesterApp* app = (LedTesterApp*)global_app; furi_timer_stop(app->timer); fu...
/** * @brief Callback for exiting the LED configuration settings. * @details This function is called when the user exits the LED configuration settings. We * stop the periodic timer to update the LEDs. * @param _context The context - unused */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L384-L393
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_tester_app_free
static void led_tester_app_free(LedTesterApp* app) { view_dispatcher_remove_view(app->view_dispatcher, LedTesterViewAbout); widget_free(app->widget_about); view_dispatcher_remove_view(app->view_dispatcher, LedTesterViewLeds); variable_item_list_free(app->variable_item_list); view_dispatcher_remove_v...
/** * @brief Free the led tester application. * @details This function frees the led tester application resources. * @param app The led tester application object. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L541-L551
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
ws2812b_led_tester_app
int32_t ws2812b_led_tester_app(void* _p) { UNUSED(_p); LedTesterApp* app = led_tester_app_alloc(); view_dispatcher_run(app->view_dispatcher); led_tester_app_free(app); return 0; }
/** * @brief Main function for led tester application. * @details This function is the entry point for the led tester application. It should be defined in * application.fam as the entry_point setting. * @param _p Input parameter - unused * @return 0 - Success */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/gpio/ws2812b_tester/app.c#L560-L566
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
hid_cc_update_timer
static void hid_cc_update_timer(HidCC* hid_cc, HidCCModel* model) { furi_assert(hid_cc); furi_assert(model); if(model->timer_click_enabled) { furi_timer_start(hid_cc->timer, model->timer_duration); } else { furi_timer_stop(hid_cc->timer); } }
// Add a new method to update the timer.
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/hid/hid_app/final_files/views/hid_cc.c#L112-L121
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
hid_cc_tick_callback
static void hid_cc_tick_callback(void* context) { furi_assert(context); HidCC* hid_cc = context; with_view_model( hid_cc->view, HidCCModel * model, { if(model->timer_click_enabled) { hid_hal_mouse_press(hid_cc->hid, HID_MOUSE_BTN_LEFT); fu...
// Add new method on tick callback that clicks button if click_enabled...
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/hid/hid_app/final_files/views/hid_cc.c#L124-L139
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_init_dma_gpio_update
static void led_driver_init_dma_gpio_update(LedDriver* led_driver, const GpioPin* gpio) { led_driver->gpio = gpio; // Memory to Peripheral led_driver->dma_gpio_update.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH; // Peripheral (GPIO - We populate GPIO port's BSRR register) led_driver->dma_gpio_upd...
/** * @brief Initializes the DMA for GPIO pin toggle via BSRR. * @param led_driver The led driver to initialize. * @param gpio The GPIO pin to toggle. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L25-L44
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_init_dma_led_transition_timer
static void led_driver_init_dma_led_transition_timer(LedDriver* led_driver) { // Timer that triggers based on user data. led_driver->dma_led_transition_timer.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH; // Peripheral (Timer - We populate TIM2's ARR register) led_driver->dma_led_transition_timer.Periph...
/** * @brief Initializes the DMA for the LED timings via ARR. * @param led_driver The led driver to initialize. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L50-L68
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_free
void led_driver_free(LedDriver* led_driver) { furi_assert(led_driver); furi_hal_gpio_init_simple(led_driver->gpio, GpioModeAnalog); free(led_driver->led_data); free(led_driver); }
/** * @brief Frees a led driver. * @details Frees a led driver. * @param led_driver The led driver to free. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L94-L100
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_set_led
uint32_t led_driver_set_led(LedDriver* led_driver, uint32_t index, uint32_t rrggbb) { furi_assert(led_driver); if(index >= led_driver->count_leds) { return 0xFFFFFFFF; } uint32_t previous = led_driver->led_data[index]; led_driver->led_data[index] = rrggbb; return previous; }
/** * @brief Sets the LED at the given index to the given color. * @note You must still call led_driver_transmit to actually update the LEDs. * @param led_driver The led driver to use. * @param index The index of the LED to set. * @param rrggbb The color to set the LED to (0xrrggbb format). * @return The previous...
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L110-L119
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_get_led
uint32_t led_driver_get_led(LedDriver* led_driver, uint32_t index) { furi_assert(led_driver); if(index >= led_driver->count_leds) { return 0xFFFFFFFF; } return led_driver->led_data[index]; }
/** * @brief Gets the LED at the given index. * @param led_driver The led driver to use. * @param index The index of the LED to get. * @return The color of the LED (0xrrggbb format). */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L127-L134
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_start_dma
static void led_driver_start_dma(LedDriver* led_driver) { furi_assert(led_driver); LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &led_driver->dma_gpio_update); LL_DMA_Init(DMA1, LL_DMA_CHANNEL_2, &led_driver->dma_led_transition_timer); LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); LL_DMA_EnableChannel(DMA1,...
/** * @brief Initializes the DMA for GPIO pin toggle and led transititions. * @param led_driver The led driver to initialize. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L140-L148
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_stop_dma
static void led_driver_stop_dma() { LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1); LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_2); LL_DMA_ClearFlag_TC1(DMA1); LL_DMA_ClearFlag_TC2(DMA1); }
/** * @brief Stops the DMA for GPIO pin toggle and led transititions. * @param led_driver The led driver to initialize. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L154-L159
89716a9b00eacce7055a75fddb5a3adde93f265f
flipper-zero-tutorials
github_2023
jamisonderek
c
led_driver_start_timer
static void led_driver_start_timer() { furi_hal_bus_enable(FuriHalBusTIM2); LL_TIM_SetCounterMode(TIM2, LL_TIM_COUNTERMODE_UP); LL_TIM_SetClockDivision(TIM2, LL_TIM_CLOCKDIVISION_DIV1); LL_TIM_SetPrescaler(TIM2, 0); // Updated by led_driver->dma_led_transition_timer.PeriphOrM2MSrcAddress LL_TIM...
/** * @brief Starts the timer for led transitions. * @param led_driver The led driver to initialize. */
https://github.com/jamisonderek/flipper-zero-tutorials/blob/89716a9b00eacce7055a75fddb5a3adde93f265f/js-old/flipboard/modules/js_rgbleds/led_driver.c#L165-L179
89716a9b00eacce7055a75fddb5a3adde93f265f