Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-gpio.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <sol-common-buildopts.h>
24 #include <sol-macros.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
63 struct sol_gpio;
64 typedef struct sol_gpio sol_gpio;
65 
82 };
83 
115 };
116 
138 };
139 
150 typedef struct sol_gpio_config {
151 #ifndef SOL_NO_API_VERSION
152 #define SOL_GPIO_CONFIG_API_VERSION (1)
153  uint16_t api_version;
154 #endif
155 
182  union {
186  struct {
211  void (*cb)(void *data, struct sol_gpio *gpio, bool value);
215  const void *user_data;
227  uint32_t poll_timeout;
228  } in;
232  struct {
236  bool value;
237  } out;
238  };
240 
252 enum sol_gpio_direction sol_gpio_direction_from_str(const char *direction)
253 #ifndef DOXYGEN_RUN
255 #endif
256  ;
257 
269 const char *sol_gpio_direction_to_str(enum sol_gpio_direction direction)
270 #ifndef DOXYGEN_RUN
271  SOL_ATTR_WARN_UNUSED_RESULT
272 #endif
273  ;
274 
286 enum sol_gpio_edge sol_gpio_edge_from_str(const char *edge)
287 #ifndef DOXYGEN_RUN
288  SOL_ATTR_WARN_UNUSED_RESULT
289 #endif
290  ;
291 
303 const char *sol_gpio_edge_to_str(enum sol_gpio_edge edge)
304 #ifndef DOXYGEN_RUN
305  SOL_ATTR_WARN_UNUSED_RESULT
306 #endif
307  ;
308 
320 enum sol_gpio_drive sol_gpio_drive_from_str(const char *drive)
321 #ifndef DOXYGEN_RUN
322  SOL_ATTR_WARN_UNUSED_RESULT
323 #endif
324  ;
325 
337 const char *sol_gpio_drive_to_str(enum sol_gpio_drive drive)
338 #ifndef DOXYGEN_RUN
339  SOL_ATTR_WARN_UNUSED_RESULT
340 #endif
341  ;
342 
360 struct sol_gpio *sol_gpio_open_by_label(const char *label, const struct sol_gpio_config *config)
361 #ifndef DOXYGEN_RUN
362  SOL_ATTR_WARN_UNUSED_RESULT
363 #endif
364  ;
365 
379 struct sol_gpio *sol_gpio_open(uint32_t pin, const struct sol_gpio_config *config)
380 #ifndef DOXYGEN_RUN
381  SOL_ATTR_WARN_UNUSED_RESULT
382 #endif
383  ;
384 
385 
399 struct sol_gpio *sol_gpio_open_raw(uint32_t pin, const struct sol_gpio_config *config)
400 #ifndef DOXYGEN_RUN
401  SOL_ATTR_WARN_UNUSED_RESULT
402 #endif
403  ;
404 
412 void sol_gpio_close(struct sol_gpio *gpio);
413 
422 bool sol_gpio_write(struct sol_gpio *gpio, bool value);
423 
431 int sol_gpio_read(struct sol_gpio *gpio);
432 
437 #ifdef __cplusplus
438 }
439 #endif
enum sol_gpio_edge trigger_mode
When to trigger events for this GPIO.
Definition: sol-gpio.h:193
enum sol_gpio_direction sol_gpio_direction_from_str(const char *direction)
Converts a string GPIO direction to sol_gpio_direction.
The GPIO is an output.
Definition: sol-gpio.h:75
struct sol_gpio_config::@31::@33 in
Configuration parameters for input GPIOs.
sol_gpio_direction
Possible values for the direction of a GPIO.
Definition: sol-gpio.h:69
bool active_low
Whether the GPIO is considered active when it's in a low state.
Definition: sol-gpio.h:174
Structure to hold the configuration of a GPIO device.
Definition: sol-gpio.h:150
int sol_gpio_read(struct sol_gpio *gpio)
Get the current value set to pin.
Events will be triggered for both edge levels.
Definition: sol-gpio.h:114
These are common Soletta macros.
const char * sol_gpio_drive_to_str(enum sol_gpio_drive drive)
Converts sol_gpio_drive to a string name.
static struct sol_buffer value
Definition: server.c:42
struct sol_gpio * sol_gpio_open_raw(uint32_t pin, const struct sol_gpio_config *config)
Opens a given pin as general purpose input or output.
struct sol_gpio sol_gpio
A handle to a GPIO.
Definition: sol-gpio.h:64
struct sol_gpio * sol_gpio_open_by_label(const char *label, const struct sol_gpio_config *config)
Opens a given pin by its board label as general purpose input or output.
const void * user_data
User data poinetr to pass to the cb function.
Definition: sol-gpio.h:215
#define SOL_ATTR_WARN_UNUSED_RESULT
Causes a warning to be emitted if a caller of the function with this attribute does not use its retur...
Definition: sol-macros.h:187
Events will be triggered on a rising edge.
Definition: sol-gpio.h:102
When set as pull-up, resistor will be connected to VCC.
Definition: sol-gpio.h:132
When set as pull-down, resistor will be connected to ground.
Definition: sol-gpio.h:137
bool sol_gpio_write(struct sol_gpio *gpio, bool value)
Set an arbitrary value to pin.
struct sol_gpio_config sol_gpio_config
Structure to hold the configuration of a GPIO device.
static struct sol_gpio * gpio
Definition: linux-micro-init.c:114
bool value
The initial value to write when the GPIO is opened.
Definition: sol-gpio.h:236
const char * sol_gpio_direction_to_str(enum sol_gpio_direction direction)
Converts sol_gpio_direction to a string name.
sol_gpio_edge
Possible values for the edge mode of a GPIO.
Definition: sol-gpio.h:89
uint32_t poll_timeout
Time to poll for events, in milliseconds.
Definition: sol-gpio.h:227
enum sol_gpio_edge sol_gpio_edge_from_str(const char *edge)
Converts a string GPIO edge to sol_gpio_edge.
enum sol_gpio_direction dir
The direction in which to open the GPIO.
Definition: sol-gpio.h:158
Events will be triggered onf a falling edge.
Definition: sol-gpio.h:108
void(* cb)(void *data, struct sol_gpio *gpio, bool value)
The function to call when an event happens.
Definition: sol-gpio.h:211
enum sol_gpio_drive drive_mode
Pull-up or pull-down resistor state for this GPIO.
Definition: sol-gpio.h:181
Do not set any state.
Definition: sol-gpio.h:127
The GPIO is an input.
Definition: sol-gpio.h:81
enum sol_gpio_drive sol_gpio_drive_from_str(const char *drive)
Converts a string GPIO drive to sol_gpio_drive.
const char * sol_gpio_edge_to_str(enum sol_gpio_edge edge)
Converts sol_gpio_edge to a string name.
void sol_gpio_close(struct sol_gpio *gpio)
Closes a given GPIO pin.
struct sol_gpio_config::@31::@34 out
Configuration parameters for output GPIOs.
sol_gpio_drive
Possible values for pull-up or pull-down resistor of a GPIO.
Definition: sol-gpio.h:123
uint16_t api_version
The API version.
Definition: sol-gpio.h:153
struct sol_gpio * sol_gpio_open(uint32_t pin, const struct sol_gpio_config *config)
Opens a given pin as general purpose input or output.
Don't generate events.
Definition: sol-gpio.h:96