File pisound-micro.c
Go to the source code of this file
#include "include/pisound-micro.h"
#include "include/pisound-micro/api_internal.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/input.h>
#include <dirent.h>
#include <stdarg.h>
#include <time.h>
#include <threads.h>
#include <stdatomic.h>
#include "utils.h"
Classes
Public Types
Public Static Attributes
Public Functions
| Type |
Name |
|
UPISND_DEFINE_STR_TO_ENUM (pin_pull, UPISND_PIN_PULL_COUNT)
|
|
UPISND_DEFINE_STR_TO_ENUM (activity, UPISND_ACTIVITY_COUNT)
|
|
UPISND_DEFINE_STR_TO_ENUM (element_type, UPISND_ELEMENT_TYPE_COUNT)
|
|
UPISND_DEFINE_STR_TO_ENUM (pin_direction, UPISND_PIN_DIR_COUNT)
|
|
UPISND_DEFINE_STR_TO_ENUM (value_mode, UPISND_VALUE_MODE_COUNT)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (0, 3, upisnd_element_type_e, element_type)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (3, 8, upisnd_pin_t, pin_id)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (11, 2, upisnd_pin_pull_e, gpio_pull)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (13, 1, upisnd_pin_direction_e, gpio_dir)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (12, 1, bool, gpio_output)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (13, 8, upisnd_pin_t, encoder_pin_b_id)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (21, 2, upisnd_pin_pull_e, encoder_pin_b_pull)
|
|
UPISND_DEFINE_INTERNAL_SETUP_FIELD (11, 2, upisnd_activity_e, activity_type)
|
Public Static Functions
| Type |
Name |
| struct upisnd_ctx_t * |
upisnd_ctx_alloc (const char * sysfs_base)
|
| void |
upisnd_ctx_free (struct upisnd_ctx_t * ctx)
|
| void |
upisnd_contexts_prepend (struct upisnd_ctx_t * ctx)
|
| int |
upisnd_contexts_remove (struct upisnd_ctx_t * ctx)
|
| struct upisnd_elements_list_node_t * |
upisnd_element_alloc (const char * name, struct upisnd_ctx_t * ctx)
|
| void |
upisnd_elements_free (upisnd_element_ref_t el)
|
| void |
upisnd_elements_prepend (struct upisnd_elements_list_node_t * node)
|
| int |
upisnd_elements_remove (upisnd_element_ref_t el)
|
| uint32_t |
upisnd_get_ms (void)
|
| struct upisnd_ctx_t * |
upisnd_set_active_ctx (struct upisnd_ctx_t * ctx)
|
| struct upisnd_ctx_t * |
upisnd_init_internal (const char * sysfs_base)
|
| int |
upisnd_path (char * path, upisnd_path_type_t type, const char * sysfs_base)
|
| int |
upisnd_open_fd (upisnd_path_type_t type, int flags, const char * sysfs_base)
|
| int |
upisnd_element_path (char * path, const char * sysfs_base, const char * name, upisnd_element_attr_e attr)
|
| int |
upisnd_element_attr_open (upisnd_element_attr_e attr, int flags, upisnd_element_ref_t el)
|
| int |
upisnd_element_attr_read_int (upisnd_element_attr_e attr, upisnd_element_ref_t el)
|
| int |
upisnd_element_attr_write_int (upisnd_element_attr_e attr, upisnd_element_ref_t el, int i)
|
| int |
upisnd_element_attr_read_str (char * dst, size_t n, upisnd_element_attr_e attr, upisnd_element_ref_t el)
|
| int |
upisnd_element_attr_write_str (upisnd_element_attr_e attr, upisnd_element_ref_t el, const char * str)
|
| int |
upisnd_unsetup_do (const char * sysfs_base, const char * name)
|
| bool |
upisnd_element_exists_in_sysfs (const char * sysfs_base, const char * name)
|
| upisnd_element_ref_t |
upisnd_setup_do (struct upisnd_ctx_t * ctx, const char * name, const char * request_fmt, ...)
|
| upisnd_pin_pull_e |
upisnd_element_get_pull (upisnd_element_ref_t el, upisnd_element_attr_e attr)
|
| int |
upisnd_unsetup_all_elements (struct upisnd_ctx_t * ctx)
|
Macros
pisound-micro_8c_1adf764cbdea00d65edcd07bb9953ad2b7
enum pisound-micro_8c_1adf764cbdea00d65edcd07bb9953ad2b7 {
UPISND_MAX_BASE_PATH_LENGTH = 64,
UPISND_ELEMENT_MAX_PATH_LENGTH = UPISND_MAX_ELEMENT_NAME_LENGTH + UPISND_MAX_BASE_PATH_LENGTH,
UPISND_MAX_REQUEST_LENGTH = UPISND_MAX_ELEMENT_NAME_LENGTH + 64
};
upisnd_path_type_t
enum upisnd_path_type_t {
UPISND_PATH_SETUP,
UPISND_PATH_UNSETUP
};
upisnd_element_attr_e
enum upisnd_element_attr_e {
UPISND_ELEMENT_ATTR_ROOT,
UPISND_ELEMENT_ATTR_TYPE,
UPISND_ELEMENT_ATTR_DIRECTION,
UPISND_ELEMENT_ATTR_PIN,
UPISND_ELEMENT_ATTR_PIN_NAME,
UPISND_ELEMENT_ATTR_PIN_PULL,
UPISND_ELEMENT_ATTR_PIN_B,
UPISND_ELEMENT_ATTR_PIN_B_NAME,
UPISND_ELEMENT_ATTR_PIN_B_PULL,
UPISND_ELEMENT_ATTR_GPIO_EXPORT,
UPISND_ELEMENT_ATTR_GPIO_UNEXPORT,
UPISND_ELEMENT_ATTR_INPUT_MIN,
UPISND_ELEMENT_ATTR_INPUT_MAX,
UPISND_ELEMENT_ATTR_VALUE_LOW,
UPISND_ELEMENT_ATTR_VALUE_HIGH,
UPISND_ELEMENT_ATTR_VALUE_MODE,
UPISND_ELEMENT_ATTR_VALUE,
UPISND_ELEMENT_ATTR_ACTIVITY_TYPE
};
UPISND_TIMEOUT_MS
const uint32_t UPISND_TIMEOUT_MS;
UPISND_TEXT_SEPARATORS
const char* const UPISND_TEXT_SEPARATORS;
UPISND_PIN_NAMES
const char const UPISND_PIN_NAMES[UPISND_PIN_COUNT][4];
UPISND_SYSFS_DEFAULT_BASE_PATH
const char UPISND_SYSFS_DEFAULT_BASE_PATH[];
UPISND_PATH_SETUP_FMT
const char UPISND_PATH_SETUP_FMT[];
UPISND_PATH_UNSETUP_FMT
const char UPISND_PATH_UNSETUP_FMT[];
UPISND_ELEMENT_PATH_ATTR_FMT
const char UPISND_ELEMENT_PATH_ATTR_FMT[];
upisnd_active_ctx
struct upisnd_ctx_t* upisnd_active_ctx;
upisnd_ctx_list
struct upisnd_ctx_t* upisnd_ctx_list;
UPISND_DEFINE_STR_TO_ENUM
UPISND_DEFINE_STR_TO_ENUM (
pin_pull,
UPISND_PIN_PULL_COUNT
)
UPISND_DEFINE_STR_TO_ENUM
UPISND_DEFINE_STR_TO_ENUM (
activity,
UPISND_ACTIVITY_COUNT
)
UPISND_DEFINE_STR_TO_ENUM
UPISND_DEFINE_STR_TO_ENUM (
element_type,
UPISND_ELEMENT_TYPE_COUNT
)
UPISND_DEFINE_STR_TO_ENUM
UPISND_DEFINE_STR_TO_ENUM (
pin_direction,
UPISND_PIN_DIR_COUNT
)
UPISND_DEFINE_STR_TO_ENUM
UPISND_DEFINE_STR_TO_ENUM (
value_mode,
UPISND_VALUE_MODE_COUNT
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
0,
3,
upisnd_element_type_e,
element_type
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
3,
8,
upisnd_pin_t,
pin_id
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
11,
2,
upisnd_pin_pull_e,
gpio_pull
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
13,
1,
upisnd_pin_direction_e,
gpio_dir
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
12,
1,
bool,
gpio_output
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
13,
8,
upisnd_pin_t,
encoder_pin_b_id
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
21,
2,
upisnd_pin_pull_e,
encoder_pin_b_pull
)
UPISND_DEFINE_INTERNAL_SETUP_FIELD
UPISND_DEFINE_INTERNAL_SETUP_FIELD (
11,
2,
upisnd_activity_e,
activity_type
)
upisnd_ctx_alloc
static struct upisnd_ctx_t * upisnd_ctx_alloc (
const char * sysfs_base
)
upisnd_ctx_free
static void upisnd_ctx_free (
struct upisnd_ctx_t * ctx
)
upisnd_contexts_prepend
static void upisnd_contexts_prepend (
struct upisnd_ctx_t * ctx
)
upisnd_contexts_remove
static int upisnd_contexts_remove (
struct upisnd_ctx_t * ctx
)
upisnd_element_alloc
static struct upisnd_elements_list_node_t * upisnd_element_alloc (
const char * name,
struct upisnd_ctx_t * ctx
)
upisnd_elements_free
static void upisnd_elements_free (
upisnd_element_ref_t el
)
upisnd_elements_prepend
static void upisnd_elements_prepend (
struct upisnd_elements_list_node_t * node
)
upisnd_elements_remove
static int upisnd_elements_remove (
upisnd_element_ref_t el
)
upisnd_get_ms
static uint32_t upisnd_get_ms (
void
)
upisnd_set_active_ctx
static struct upisnd_ctx_t * upisnd_set_active_ctx (
struct upisnd_ctx_t * ctx
)
upisnd_init_internal
static struct upisnd_ctx_t * upisnd_init_internal (
const char * sysfs_base
)
upisnd_path
static int upisnd_path (
char * path,
upisnd_path_type_t type,
const char * sysfs_base
)
upisnd_open_fd
static int upisnd_open_fd (
upisnd_path_type_t type,
int flags,
const char * sysfs_base
)
upisnd_element_path
static int upisnd_element_path (
char * path,
const char * sysfs_base,
const char * name,
upisnd_element_attr_e attr
)
upisnd_element_attr_open
static int upisnd_element_attr_open (
upisnd_element_attr_e attr,
int flags,
upisnd_element_ref_t el
)
upisnd_element_attr_read_int
static int upisnd_element_attr_read_int (
upisnd_element_attr_e attr,
upisnd_element_ref_t el
)
upisnd_element_attr_write_int
static int upisnd_element_attr_write_int (
upisnd_element_attr_e attr,
upisnd_element_ref_t el,
int i
)
upisnd_element_attr_read_str
static int upisnd_element_attr_read_str (
char * dst,
size_t n,
upisnd_element_attr_e attr,
upisnd_element_ref_t el
)
upisnd_element_attr_write_str
static int upisnd_element_attr_write_str (
upisnd_element_attr_e attr,
upisnd_element_ref_t el,
const char * str
)
upisnd_unsetup_do
static int upisnd_unsetup_do (
const char * sysfs_base,
const char * name
)
upisnd_element_exists_in_sysfs
static bool upisnd_element_exists_in_sysfs (
const char * sysfs_base,
const char * name
)
upisnd_setup_do
static upisnd_element_ref_t upisnd_setup_do (
struct upisnd_ctx_t * ctx,
const char * name,
const char * request_fmt,
...
)
upisnd_element_get_pull
static upisnd_pin_pull_e upisnd_element_get_pull (
upisnd_element_ref_t el,
upisnd_element_attr_e attr
)
upisnd_unsetup_all_elements
static int upisnd_unsetup_all_elements (
struct upisnd_ctx_t * ctx
)
Macro Definition Documentation
UPISND_DEFINE_STR_TO_ENUM
#define UPISND_DEFINE_STR_TO_ENUM (
middle_part,
count
) `/* multi line expression */`
UPISND_DEFINE_INTERNAL_SETUP_FIELD
#define UPISND_DEFINE_INTERNAL_SETUP_FIELD (
shift,
bits,
type,
name
) `/* multi line expression */`
UPISND_DO_WITH_ERR_CHECK
#define UPISND_DO_WITH_ERR_CHECK (
x
) `if ((err = (x)) < 0) { return err; }`