libjoybus
Joybus implementation for 32-bit MCUs
Loading...
Searching...
No Matches
target.h
1
28
29#pragma once
30
31#include <stdbool.h>
32#include <stdint.h>
33
34struct joybus_target;
35
37#define JOYBUS_TARGET(target) ((struct joybus_target *)(target))
38
46typedef void (*joybus_target_response_cb)(const uint8_t *response, uint8_t len, void *user_data);
47
62 int (*byte_received)(struct joybus_target *target, const uint8_t *command, uint8_t byte_idx,
63 joybus_target_response_cb send_response, void *user_data);
64};
65
71 const struct joybus_target_api *api;
72
75};
76
87static inline int joybus_target_byte_received(struct joybus_target *target, const uint8_t *command, uint8_t byte_idx,
88 joybus_target_response_cb send_response, void *user_data)
89{
90 return target->api->byte_received(target, command, byte_idx, send_response, user_data);
91}
92
99static inline bool joybus_target_is_registered(struct joybus_target *target)
100{
101 return target->registered;
102}
103
static int joybus_target_byte_received(struct joybus_target *target, const uint8_t *command, uint8_t byte_idx, joybus_target_response_cb send_response, void *user_data)
Handle a received command byte for a Joybus target.
Definition target.h:87
void(* joybus_target_response_cb)(const uint8_t *response, uint8_t len, void *user_data)
Callback type for sending responses from target command handlers.
Definition target.h:46
static bool joybus_target_is_registered(struct joybus_target *target)
Check if a target is currently registered on the bus.
Definition target.h:99
API for implementing a Joybus target.
Definition target.h:51
int(* byte_received)(struct joybus_target *target, const uint8_t *command, uint8_t byte_idx, joybus_target_response_cb send_response, void *user_data)
Handle a received command byte.
Definition target.h:62
Interface for a Joybus target, a device on the Joybus which responds to commands from a host.
Definition target.h:69
bool registered
Whether the target is currently registered on the bus.
Definition target.h:74
const struct joybus_target_api * api
API for handling received commands.
Definition target.h:71