src/peripheral_pwm.c
src/peripheral_uart.c
src/peripheral_spi.c
- src/interface/gpio.c
- src/interface/i2c.c
- src/interface/pwm.c
- src/interface/spi.c
- src/interface/uart.c
+ src/interface/peripheral_interface_gpio.c
+ src/interface/peripheral_interface_i2c.c
+ src/interface/peripheral_interface_pwm.c
+ src/interface/peripheral_interface_spi.c
+ src/interface/peripheral_interface_uart.c
src/peripheral_gdbus_gpio.c
src/peripheral_gdbus_i2c.c
src/peripheral_gdbus_pwm.c
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __GPIO_H__
-#define __GPIO_H__
-
-#include "peripheral_io.h"
-
-#define SYSFS_GPIO_DIR "/sys/class/gpio"
-#define GPIO_BUFFER_MAX 64
-
-typedef enum {
- GPIO_DIRECTION_IN = 0,
- GPIO_DIRECTION_OUT_HIGH = 1,
- GPIO_DIRECTION_OUT_LOW = 2,
-} gpio_direction_e;
-
-typedef enum {
- GPIO_EDGE_NONE = 0,
- GPIO_EDGE_RISING = 1,
- GPIO_EDGE_FALLING = 2,
- GPIO_EDGE_BOTH = 3,
-} gpio_edge_e;
-
-int gpio_close(peripheral_gpio_h gpio);
-int gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge);
-int gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir);
-int gpio_write(peripheral_gpio_h gpio, int value);
-int gpio_read(peripheral_gpio_h gpio, int *value);
-
-int gpio_open_isr(peripheral_gpio_h gpio);
-int gpio_close_isr(peripheral_gpio_h gpio);
-#endif/*__GPIO_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __I2C_H__
-#define __I2C_H__
-
-#include <stdint.h>
-
-#include "peripheral_io.h"
-
-#define SYSFS_I2C_DIR "/dev/i2c"
-#define I2C_BUFFER_MAX 64
-
-#define I2C_SLAVE 0x0703 /* Use this slave address */
-#define I2C_SMBUS 0x0720 /* SMBus transfer */
-
-/* i2c_smbus_xfer read or write markers */
-#define I2C_SMBUS_READ 1
-#define I2C_SMBUS_WRITE 0
-
-/* SMBus transaction types */
-#define I2C_SMBUS_QUICK 0
-#define I2C_SMBUS_BYTE 1
-#define I2C_SMBUS_BYTE_DATA 2
-#define I2C_SMBUS_WORD_DATA 3
-
-/*
- * Data for SMBus Messages
- */
-#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
-
-union i2c_smbus_data {
- uint8_t byte;
- uint16_t word;
- uint8_t block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
- /* and one more for user-space compatibility */
-};
-
-/* This is the structure as used in the I2C_SMBUS ioctl call */
-struct i2c_smbus_ioctl_data {
- uint8_t read_write;
- uint8_t command;
- uint32_t size;
- union i2c_smbus_data *data;
-};
-
-int i2c_close(peripheral_i2c_h i2c);
-int i2c_set_address(peripheral_i2c_h i2c, int address);
-int i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length);
-int i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length);
-int i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data);
-
-#endif/* __I2C_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_INTERFACE_GPIO_H__
+#define __PERIPHERAL_INTERFACE_GPIO_H__
+
+#include "peripheral_io.h"
+
+#define SYSFS_GPIO_DIR "/sys/class/gpio"
+#define GPIO_BUFFER_MAX 64
+
+typedef enum {
+ GPIO_DIRECTION_IN = 0,
+ GPIO_DIRECTION_OUT_HIGH = 1,
+ GPIO_DIRECTION_OUT_LOW = 2,
+} gpio_direction_e;
+
+typedef enum {
+ GPIO_EDGE_NONE = 0,
+ GPIO_EDGE_RISING = 1,
+ GPIO_EDGE_FALLING = 2,
+ GPIO_EDGE_BOTH = 3,
+} gpio_edge_e;
+
+int peripheral_interface_gpio_close(peripheral_gpio_h gpio);
+int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge);
+int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir);
+int peripheral_interface_gpio_write(peripheral_gpio_h gpio, int value);
+int peripheral_interface_gpio_read(peripheral_gpio_h gpio, int *value);
+
+int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio);
+int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio);
+
+#endif/*__PERIPHERAL_INTERFACE_GPIO_H__*/
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_INTERFACE_I2C_H__
+#define __PERIPHERAL_INTERFACE_I2C_H__
+
+#include <stdint.h>
+
+#include "peripheral_io.h"
+
+#define SYSFS_I2C_DIR "/dev/i2c"
+#define I2C_BUFFER_MAX 64
+
+#define I2C_SLAVE 0x0703 /* Use this slave address */
+#define I2C_SMBUS 0x0720 /* SMBus transfer */
+
+/* i2c_smbus_xfer read or write markers */
+#define I2C_SMBUS_READ 1
+#define I2C_SMBUS_WRITE 0
+
+/* SMBus transaction types */
+#define I2C_SMBUS_QUICK 0
+#define I2C_SMBUS_BYTE 1
+#define I2C_SMBUS_BYTE_DATA 2
+#define I2C_SMBUS_WORD_DATA 3
+
+/*
+ * Data for SMBus Messages
+ */
+#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
+
+union i2c_smbus_data {
+ uint8_t byte;
+ uint16_t word;
+ uint8_t block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
+ /* and one more for user-space compatibility */
+};
+
+/* This is the structure as used in the I2C_SMBUS ioctl call */
+struct i2c_smbus_ioctl_data {
+ uint8_t read_write;
+ uint8_t command;
+ uint32_t size;
+ union i2c_smbus_data *data;
+};
+
+int peripheral_interface_i2c_close(peripheral_i2c_h i2c);
+int peripheral_interface_i2c_set_address(peripheral_i2c_h i2c, int address);
+int peripheral_interface_i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length);
+int peripheral_interface_i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length);
+int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data);
+
+#endif/* __PERIPHERAL_INTERFACE_I2C_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_INTERFACE_PWM_H__
+#define __PERIPHERAL_INTERFACE_PWM_H__
+
+#include "peripheral_io.h"
+
+/**
+ * @brief Enumeration for Polarity
+ */
+typedef enum {
+ PWM_POLARITY_NORMAL = 0,
+ PWM_POLARITY_INVERSED,
+} pwm_polarity_e;
+
+
+/**
+* @brief pwm_close() deinit pwm pin.
+*
+* @param[in] chip pwm chip number
+* @param[in] pin pwm pin number
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_pwm_close(peripheral_pwm_h pwm);
+
+/**
+* @brief pwm_set_period() sets the pwm period.
+*
+* @param[in] chip pwm chip number
+* @param[in] pin pwm pin number
+* @param[in] period pwm period
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, int period);
+
+/**
+* @brief pwm_set_duty_cycle() sets the pwm duty cycle.
+*
+* @param[in] chip pwm chip number
+* @param[in] pin pwm pin number
+* @param[in] duty_cycle pwm duty cycle
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle);
+
+/**
+* @brief pwm_set_polarity() sets the pwm polarity.
+*
+* @param[in] chip pwm chip number
+* @param[in] pin pwm pin number
+* @param[in] polarity pwm polarity
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity);
+
+/**
+* @brief pwm_set_enable() sets the pwm state.
+*
+* @param[in] chip pwm chip number
+* @param[in] pin pwm pin number
+* @param[in] enable pwm enable/disabled state value
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable);
+
+#endif /* __PERIPHERAL_INTERFACE_PWM_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_INTERFACE_SPI_H__
+#define __PERIPHERAL_INTERFACE_SPI_H__
+
+#include "peripheral_io.h"
+
+int peripheral_interface_spi_close(peripheral_spi_h spi);
+int peripheral_interface_spi_set_mode(peripheral_spi_h spi, unsigned char mode);
+int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb);
+int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
+int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, unsigned int freq);
+int peripheral_interface_spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length);
+int peripheral_interface_spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length);
+int peripheral_interface_spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length);
+
+#endif /* __PERIPHERAL_INTERFACE_SPI_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_INTERFACE_UART_H__
+#define __PERIPHERAL_INTERFACE_UART_H__
+
+#include "peripheral_io.h"
+
+#include <stdint.h>
+
+/**
+ * @brief Enumeration for Baud Rate
+ */
+typedef enum {
+ UART_BAUD_RATE_0 = 0,
+ UART_BAUD_RATE_50,
+ UART_BAUD_RATE_75,
+ UART_BAUD_RATE_110,
+ UART_BAUD_RATE_134,
+ UART_BAUD_RATE_150,
+ UART_BAUD_RATE_200,
+ UART_BAUD_RATE_300,
+ UART_BAUD_RATE_600,
+ UART_BAUD_RATE_1200,
+ UART_BAUD_RATE_1800,
+ UART_BAUD_RATE_2400,
+ UART_BAUD_RATE_4800,
+ UART_BAUD_RATE_9600,
+ UART_BAUD_RATE_19200,
+ UART_BAUD_RATE_38400,
+ UART_BAUD_RATE_57600,
+ UART_BAUD_RATE_115200,
+ UART_BAUD_RATE_230400
+} uart_baud_rate_e;
+
+/**
+ * @brief Enumeration for Byte Size
+ */
+typedef enum {
+ UART_BYTE_SIZE_5BIT = 0,
+ UART_BYTE_SIZE_6BIT,
+ UART_BYTE_SIZE_7BIT,
+ UART_BYTE_SIZE_8BIT
+} uart_byte_size_e;
+
+/**
+ * @brief Enumeration of Parity Bit
+ */
+typedef enum {
+ UART_PARITY_NONE = 0,
+ UART_PARITY_EVEN,
+ UART_PARITY_ODD
+} uart_parity_e;
+
+/**
+ * @brief Enumeration for Stop Bits
+ */
+typedef enum {
+ UART_STOP_BITS_1BIT = 0,
+ UART_STOP_BITS_2BIT
+} uart_stop_bits_e;
+
+/**
+* @brief uart_close() closes uart port.
+*
+* @param[in] file_hndl handle of uart_context
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_close(peripheral_uart_h uart);
+
+/**
+* @brief uart_flush() flushes uart buffer.
+*
+* @param[in] file_hndl handle of uart_context
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_flush(peripheral_uart_h uart);
+
+/**
+* @brief uart_set_baudrate() sets uart baud rate.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] baud uart baud rate
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud);
+
+/**
+* @brief uart_set_mode() sets byte size, parity bit and stop bits.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] byte_size uart byte size
+* @param[in] parity uart parity type (even/odd/none)
+* @param[in] stop_bits uart stop bits
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits);
+
+/**
+* @brief peripheral_bus_uart_set_byte_size() set byte size.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] byte_size uart byte size
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size);
+
+/**
+* @brief peripheral_bus_uart_set_parity() set parity bit.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] parity uart parity type (even/odd/none)
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e parity);
+
+/**
+* @brief peripheral_bus_uart_set_stop_bits() set stop bits.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] stop_bits uart stop bits
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits);
+
+/**
+* @brief uart_set_flow_control() set flow control settings.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] xonxoff ixon/ixoff
+* @param[in] rtscts rts/cts
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts);
+
+/**
+* @brief uart_read() reads data over uart bus.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] buf the pointer of data buffer
+* @param[in] length size to read
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length);
+
+/**
+* @brief uart_write() writes data over uart bus.
+*
+* @param[in] file_hndl handle of uart_context
+* @param[in] buf the pointer of data buffer
+* @param[in] length size to write
+* @return On success, 0 is returned. On failure, a negative value is returned.
+*/
+int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length);
+
+#endif /* __PERIPHERAL_INTERFACE_UART_H__ */
+
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __PWM_H__
-#define __PWM_H__
-
-#include "peripheral_io.h"
-
-/**
- * @brief Enumeration for Polarity
- */
-typedef enum {
- PWM_POLARITY_NORMAL = 0,
- PWM_POLARITY_INVERSED,
-} pwm_polarity_e;
-
-
-/**
-* @brief pwm_close() deinit pwm pin.
-*
-* @param[in] chip pwm chip number
-* @param[in] pin pwm pin number
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int pwm_close(peripheral_pwm_h pwm);
-
-/**
-* @brief pwm_set_period() sets the pwm period.
-*
-* @param[in] chip pwm chip number
-* @param[in] pin pwm pin number
-* @param[in] period pwm period
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int pwm_set_period(peripheral_pwm_h pwm, int period);
-
-/**
-* @brief pwm_set_duty_cycle() sets the pwm duty cycle.
-*
-* @param[in] chip pwm chip number
-* @param[in] pin pwm pin number
-* @param[in] duty_cycle pwm duty cycle
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle);
-
-/**
-* @brief pwm_set_polarity() sets the pwm polarity.
-*
-* @param[in] chip pwm chip number
-* @param[in] pin pwm pin number
-* @param[in] polarity pwm polarity
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity);
-
-/**
-* @brief pwm_set_enable() sets the pwm state.
-*
-* @param[in] chip pwm chip number
-* @param[in] pin pwm pin number
-* @param[in] enable pwm enable/disabled state value
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int pwm_set_enable(peripheral_pwm_h pwm, bool enable);
-
-#endif /* __PWM_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __SPI_H__
-#define __SPI_H__
-
-#include "peripheral_io.h"
-
-int spi_close(peripheral_spi_h spi);
-int spi_set_mode(peripheral_spi_h spi, unsigned char mode);
-int spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb);
-int spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
-int spi_set_frequency(peripheral_spi_h spi, unsigned int freq);
-int spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length);
-int spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length);
-int spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length);
-
-#endif /* __SPI_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __UART_H__
-#define __UART_H__
-
-#include "peripheral_io.h"
-
-#include <stdint.h>
-
-/**
- * @brief Enumeration for Baud Rate
- */
-typedef enum {
- UART_BAUD_RATE_0 = 0,
- UART_BAUD_RATE_50,
- UART_BAUD_RATE_75,
- UART_BAUD_RATE_110,
- UART_BAUD_RATE_134,
- UART_BAUD_RATE_150,
- UART_BAUD_RATE_200,
- UART_BAUD_RATE_300,
- UART_BAUD_RATE_600,
- UART_BAUD_RATE_1200,
- UART_BAUD_RATE_1800,
- UART_BAUD_RATE_2400,
- UART_BAUD_RATE_4800,
- UART_BAUD_RATE_9600,
- UART_BAUD_RATE_19200,
- UART_BAUD_RATE_38400,
- UART_BAUD_RATE_57600,
- UART_BAUD_RATE_115200,
- UART_BAUD_RATE_230400
-} uart_baud_rate_e;
-
-/**
- * @brief Enumeration for Byte Size
- */
-typedef enum {
- UART_BYTE_SIZE_5BIT = 0,
- UART_BYTE_SIZE_6BIT,
- UART_BYTE_SIZE_7BIT,
- UART_BYTE_SIZE_8BIT
-} uart_byte_size_e;
-
-/**
- * @brief Enumeration of Parity Bit
- */
-typedef enum {
- UART_PARITY_NONE = 0,
- UART_PARITY_EVEN,
- UART_PARITY_ODD
-} uart_parity_e;
-
-/**
- * @brief Enumeration for Stop Bits
- */
-typedef enum {
- UART_STOP_BITS_1BIT = 0,
- UART_STOP_BITS_2BIT
-} uart_stop_bits_e;
-
-/**
-* @brief uart_close() closes uart port.
-*
-* @param[in] file_hndl handle of uart_context
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_close(peripheral_uart_h uart);
-
-/**
-* @brief uart_flush() flushes uart buffer.
-*
-* @param[in] file_hndl handle of uart_context
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_flush(peripheral_uart_h uart);
-
-/**
-* @brief uart_set_baudrate() sets uart baud rate.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] baud uart baud rate
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud);
-
-/**
-* @brief uart_set_mode() sets byte size, parity bit and stop bits.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] byte_size uart byte size
-* @param[in] parity uart parity type (even/odd/none)
-* @param[in] stop_bits uart stop bits
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits);
-
-/**
-* @brief peripheral_bus_uart_set_byte_size() set byte size.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] byte_size uart byte size
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size);
-
-/**
-* @brief peripheral_bus_uart_set_parity() set parity bit.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] parity uart parity type (even/odd/none)
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity);
-
-/**
-* @brief peripheral_bus_uart_set_stop_bits() set stop bits.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] stop_bits uart stop bits
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits);
-
-/**
-* @brief uart_set_flow_control() set flow control settings.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] xonxoff ixon/ixoff
-* @param[in] rtscts rts/cts
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts);
-
-/**
-* @brief uart_read() reads data over uart bus.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] buf the pointer of data buffer
-* @param[in] length size to read
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length);
-
-/**
-* @brief uart_write() writes data over uart bus.
-*
-* @param[in] file_hndl handle of uart_context
-* @param[in] buf the pointer of data buffer
-* @param[in] length size to write
-* @return On success, 0 is returned. On failure, a negative value is returned.
-*/
-int uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length);
-
-#endif /* __UART_H__ */
-
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <poll.h>
-
-#include "gpio.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-
-#define MAX_ERR_LEN 255
-
-int gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir)
-{
- int status;
-
- if (dir == GPIO_DIRECTION_IN)
- status = write(gpio->fd_direction, "in", strlen("in")+1);
- else if (dir == GPIO_DIRECTION_OUT_HIGH)
- status = write(gpio->fd_direction, "high", strlen("high")+1);
- else if (dir == GPIO_DIRECTION_OUT_LOW)
- status = write(gpio->fd_direction, "low", strlen("low")+1);
- else {
- _E("Error: gpio direction is wrong\n");
- return -EIO;
- }
-
- if (status <= 0) {
- _E("Error: gpio direction set error\n");
- return -EIO;
- }
-
- return 0;
-}
-
-int gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge)
-{
- int status;
-
- if (edge == GPIO_EDGE_NONE)
- status = write(gpio->fd_edge, "none", strlen("none")+1);
- else if (edge == GPIO_EDGE_RISING)
- status = write(gpio->fd_edge, "rising", strlen("rising")+1);
- else if (edge == GPIO_EDGE_FALLING)
- status = write(gpio->fd_edge, "falling", strlen("falling")+1);
- else if (edge == GPIO_EDGE_BOTH)
- status = write(gpio->fd_edge, "both", strlen("both")+1);
- else {
- _E("Error: gpio edge is wrong\n");
- return -EIO;
- }
-
- if (status <= 0) {
- _E("Error: gpio edge set error\n");
- return -EIO;
- }
-
- return 0;
-}
-
-int gpio_write(peripheral_gpio_h gpio, int value)
-{
- int status;
-
- if (value == 1)
- status = write(gpio->fd_value, "1", strlen("1")+1);
- else if (value == 0)
- status = write(gpio->fd_value, "0", strlen("0")+1);
- else {
- _E("Error: gpio write value error \n");
- return -EIO;
- }
-
- if (status <= 0) {
- _E("Error: gpio write error\n");
- return -EIO;
- }
-
- return 0;
-}
-
-int gpio_read(peripheral_gpio_h gpio, int *value)
-{
- int len;
- char gpio_buf[GPIO_BUFFER_MAX] = {0, };
-
- len = read(gpio->fd_value, &gpio_buf, 1);
- if (len <= 0) {
- _E("Error: gpio read error \n");
- return -EIO;
- }
-
- if (0 == strncmp(gpio_buf, "1", strlen("1")))
- *value = 1;
- else if (0 == strncmp(gpio_buf, "0", strlen("0")))
- *value = 0;
- else {
- _E("Error: gpio value is error \n");
- return -EIO;
- }
-
- return 0;
-}
-
-int gpio_close(peripheral_gpio_h gpio)
-{
- int status;
-
- status = close(gpio->fd_direction);
- if (status < 0) {
- _E("Error: gpio direction fd close error \n");
- return -EIO;
- }
-
- status = close(gpio->fd_edge);
- if (status < 0) {
- _E("Error: gpio edge fd close error \n");
- return -EIO;
- }
-
- status = close(gpio->fd_value);
- if (status < 0) {
- _E("Error: gpio value fd close error \n");
- return -EIO;
- }
-
- return 0;
-}
-
-int gpio_open_isr(peripheral_gpio_h gpio)
-{
- // int fd;
- // char gpio_dev[GPIO_BUFFER_MAX] = {0, };
-
- // snprintf(gpio_dev, sizeof(gpio_dev)-1, SYSFS_GPIO_DIR"/gpio%d/value", gpiopin);
-
- // _D("open isr string [%s]", gpio_dev);
-
- // fd = open(gpio_dev, O_RDONLY);
- // if (fd < 0) {
- // char errmsg[MAX_ERR_LEN];
- // strerror_r(errno, errmsg, MAX_ERR_LEN);
- // _E("Can't Open /sys/class/gpio/gpio%d pin value: %s\n", gpiopin, errmsg);
- // return -ENXIO;
- // }
-
- // return fd;
-
- return 0;
-}
-
-int gpio_close_isr(peripheral_gpio_h gpio)
-{
-// if (fd <= 0) return -EINVAL;
-
-// close(fd);
-
- return 0;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-
-#include "i2c.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-
-#define MAX_ERR_LEN 255
-
-int i2c_close(peripheral_i2c_h i2c)
-{
- int status;
-
- _D("fd : %d", i2c->fd);
- RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd");
-
- status = close(i2c->fd);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to close fd : %d", i2c->fd);
- return -EIO;
- }
-
- return 0;
-}
-
-int i2c_set_address(peripheral_i2c_h i2c, int address)
-{
- int status;
-
- _D("fd : %d, slave address : 0x%x", i2c->fd, address);
- RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd");
-
- status = ioctl(i2c->fd, I2C_SLAVE, address);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to set slave address(%x), fd : %d, errmsg : %s", address, i2c->fd, errmsg);
- return status;
- }
-
- return 0;
-}
-
-int i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length)
-{
- int status;
-
- RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd);
-
- status = read(i2c->fd, data, length);
- if (status != length) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("i2c read failed, fd : %d, errmsg : %s", i2c->fd, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length)
-{
- int status;
-
- RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd);
-
- status = write(i2c->fd, data, length);
- if (status != length) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("i2c write failed fd : %d, errmsg : %s", i2c->fd, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data)
-{
- int status;
-
- RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd);
-
- status = ioctl(i2c->fd, I2C_SMBUS, data);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("i2c transaction failed fd : %d, errmsg : %s", i2c->fd, errmsg);
- return -EIO;
- }
-
- return 0;
-}
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+
+#include "peripheral_interface_gpio.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+
+#define MAX_ERR_LEN 255
+
+int peripheral_interface_gpio_set_direction(peripheral_gpio_h gpio, gpio_direction_e dir)
+{
+ int status;
+
+ if (dir == GPIO_DIRECTION_IN)
+ status = write(gpio->fd_direction, "in", strlen("in")+1);
+ else if (dir == GPIO_DIRECTION_OUT_HIGH)
+ status = write(gpio->fd_direction, "high", strlen("high")+1);
+ else if (dir == GPIO_DIRECTION_OUT_LOW)
+ status = write(gpio->fd_direction, "low", strlen("low")+1);
+ else {
+ _E("Error: gpio direction is wrong\n");
+ return -EIO;
+ }
+
+ if (status <= 0) {
+ _E("Error: gpio direction set error\n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_gpio_set_edge_mode(peripheral_gpio_h gpio, gpio_edge_e edge)
+{
+ int status;
+
+ if (edge == GPIO_EDGE_NONE)
+ status = write(gpio->fd_edge, "none", strlen("none")+1);
+ else if (edge == GPIO_EDGE_RISING)
+ status = write(gpio->fd_edge, "rising", strlen("rising")+1);
+ else if (edge == GPIO_EDGE_FALLING)
+ status = write(gpio->fd_edge, "falling", strlen("falling")+1);
+ else if (edge == GPIO_EDGE_BOTH)
+ status = write(gpio->fd_edge, "both", strlen("both")+1);
+ else {
+ _E("Error: gpio edge is wrong\n");
+ return -EIO;
+ }
+
+ if (status <= 0) {
+ _E("Error: gpio edge set error\n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_gpio_write(peripheral_gpio_h gpio, int value)
+{
+ int status;
+
+ if (value == 1)
+ status = write(gpio->fd_value, "1", strlen("1")+1);
+ else if (value == 0)
+ status = write(gpio->fd_value, "0", strlen("0")+1);
+ else {
+ _E("Error: gpio write value error \n");
+ return -EIO;
+ }
+
+ if (status <= 0) {
+ _E("Error: gpio write error\n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_gpio_read(peripheral_gpio_h gpio, int *value)
+{
+ int len;
+ char gpio_buf[GPIO_BUFFER_MAX] = {0, };
+
+ len = read(gpio->fd_value, &gpio_buf, 1);
+ if (len <= 0) {
+ _E("Error: gpio read error \n");
+ return -EIO;
+ }
+
+ if (0 == strncmp(gpio_buf, "1", strlen("1")))
+ *value = 1;
+ else if (0 == strncmp(gpio_buf, "0", strlen("0")))
+ *value = 0;
+ else {
+ _E("Error: gpio value is error \n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_gpio_close(peripheral_gpio_h gpio)
+{
+ int status;
+
+ status = close(gpio->fd_direction);
+ if (status < 0) {
+ _E("Error: gpio direction fd close error \n");
+ return -EIO;
+ }
+
+ status = close(gpio->fd_edge);
+ if (status < 0) {
+ _E("Error: gpio edge fd close error \n");
+ return -EIO;
+ }
+
+ status = close(gpio->fd_value);
+ if (status < 0) {
+ _E("Error: gpio value fd close error \n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_gpio_open_isr(peripheral_gpio_h gpio)
+{
+ // TODO: set interrupted callback function
+
+ return 0;
+}
+
+int peripheral_interface_gpio_close_isr(peripheral_gpio_h gpio)
+{
+ // TODO: unset interrupted callback function
+
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include "peripheral_interface_i2c.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+
+#define MAX_ERR_LEN 255
+
+int peripheral_interface_i2c_close(peripheral_i2c_h i2c)
+{
+ int status;
+
+ _D("fd : %d", i2c->fd);
+ RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd");
+
+ status = close(i2c->fd);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to close fd : %d", i2c->fd);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_i2c_set_address(peripheral_i2c_h i2c, int address)
+{
+ int status;
+
+ _D("fd : %d, slave address : 0x%x", i2c->fd, address);
+ RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd");
+
+ status = ioctl(i2c->fd, I2C_SLAVE, address);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to set slave address(%x), fd : %d, errmsg : %s", address, i2c->fd, errmsg);
+ return status;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_i2c_read(peripheral_i2c_h i2c, unsigned char *data, int length)
+{
+ int status;
+
+ RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd);
+
+ status = read(i2c->fd, data, length);
+ if (status != length) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("i2c read failed, fd : %d, errmsg : %s", i2c->fd, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_i2c_write(peripheral_i2c_h i2c, const unsigned char *data, int length)
+{
+ int status;
+
+ RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd);
+
+ status = write(i2c->fd, data, length);
+ if (status != length) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("i2c write failed fd : %d, errmsg : %s", i2c->fd, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_i2c_smbus_ioctl(peripheral_i2c_h i2c, struct i2c_smbus_ioctl_data *data)
+{
+ int status;
+
+ RETVM_IF(i2c->fd < 0, -EINVAL, "Invalid fd : %d", i2c->fd);
+
+ status = ioctl(i2c->fd, I2C_SMBUS, data);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("i2c transaction failed fd : %d, errmsg : %s", i2c->fd, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include "peripheral_interface_pwm.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+
+#define SYSFS_PWM_PATH "/sys/class/pwm"
+
+#define PATH_BUF_MAX 64
+#define PWM_BUF_MAX 16
+#define MAX_ERR_LEN 255
+
+int peripheral_interface_pwm_close(peripheral_pwm_h pwm)
+{
+ int status;
+
+ status = close(pwm->fd_period);
+ if (status < 0) {
+ _E("Error: pwm period fd close error \n");
+ return -EIO;
+ }
+
+ status = close(pwm->fd_duty_cycle);
+ if (status < 0) {
+ _E("Error: pwm duty cycle fd close error \n");
+ return -EIO;
+ }
+
+ status = close(pwm->fd_polarity);
+ if (status < 0) {
+ _E("Error: pwm polarity fd close error \n");
+ return -EIO;
+ }
+
+ status = close(pwm->fd_enable);
+ if (status < 0) {
+ _E("Error: pwm enable fd close error \n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_pwm_set_period(peripheral_pwm_h pwm, int period)
+{
+ int len, status;
+ char pwm_buf[PWM_BUF_MAX] = {0};
+
+ len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period);
+ status = write(pwm->fd_period, pwm_buf, len);
+ if (status < 0) {
+ _E("Failed to set period");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
+{
+ int len, status;
+ char pwm_buf[PWM_BUF_MAX] = {0};
+
+ len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle);
+ status = write(pwm->fd_duty_cycle, pwm_buf, len);
+ if (status < 0) {
+ _E("Failed to set duty cycle");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity)
+{
+ int status;
+
+ if (polarity == PWM_POLARITY_NORMAL)
+ status = write(pwm->fd_polarity, "normal", strlen("normal")+1);
+ else if (polarity == PWM_POLARITY_INVERSED)
+ status = write(pwm->fd_polarity, "inversed", strlen("inversed")+1);
+ else {
+ _E("Invalid pwm polarity : %d", polarity);
+ return -EINVAL;
+ }
+
+ if (status <= 0) {
+ _E("Failed to set polarity");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_pwm_set_enable(peripheral_pwm_h pwm, bool enable)
+{
+ int len, status;
+ char pwm_buf[PWM_BUF_MAX] = {0};
+
+ len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", enable);
+ status = write(pwm->fd_enable, pwm_buf, len);
+ if (status < 0) {
+ _E("Failed to set enable");
+ return -EIO;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/spi/spidev.h>
+
+#include "peripheral_interface_spi.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+
+#define SYSFS_SPI_DIR "/dev/spidev"
+#define SYSFS_SPI_BUFSIZ "/sys/module/spidev/parameters/bufsiz"
+#define SPI_BUFFER_MAX 64
+#define MAX_ERR_LEN 255
+
+int peripheral_interface_spi_close(peripheral_spi_h spi)
+{
+ int status;
+
+ _D("fd : %d", spi->fd);
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
+
+ status = close(spi->fd);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to close fd : %d", spi->fd);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_spi_set_mode(peripheral_spi_h spi, unsigned char mode)
+{
+ int status;
+
+ _D("fd : %d, mode : %d", spi->fd, mode);
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
+
+ status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to set mode(%d) : %s", mode, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb)
+{
+ int status;
+
+ _D("fd : %d, lsb : %d", spi->fd, lsb);
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
+
+ status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &lsb);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", lsb, spi->fd, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits)
+{
+ int status;
+
+ _D("fd : %d, bits : %d", spi->fd, bits);
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
+
+ status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to set bits(%d), fd : %d, errmsg : %s", bits, spi->fd, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_spi_set_frequency(peripheral_spi_h spi, unsigned int freq)
+{
+ int status;
+
+ _D("fd : %d, freq : %d", spi->fd, freq);
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
+
+ status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to set frequency(%d), fd : %d, errmsg : %s", freq, spi->fd, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length)
+{
+ int status;
+ struct spi_ioc_transfer xfer;
+
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd);
+
+ memset(&xfer, 0, sizeof(struct spi_ioc_transfer));
+ xfer.rx_buf = (unsigned long)rxbuf;
+ xfer.len = length;
+
+ status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to read data, fd : %d, length : %d, errmsg : %s", spi->fd, length, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length)
+{
+ int status;
+ struct spi_ioc_transfer xfer;
+
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd);
+
+ memset(&xfer, 0, sizeof(struct spi_ioc_transfer));
+ xfer.tx_buf = (unsigned long)txbuf;
+ xfer.len = length;
+
+ status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to write data(%d) : %s", length, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length)
+{
+ int status;
+ struct spi_ioc_transfer xfer;
+
+ RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd);
+
+ if (!txbuf || !rxbuf || length < 0) return -EINVAL;
+
+ memset(&xfer, 0, sizeof(xfer));
+ xfer.tx_buf = (unsigned long)txbuf;
+ xfer.rx_buf = (unsigned long)rxbuf;
+ xfer.len = length;
+
+ status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to exchange data(%d) : %s", length, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <termios.h>
+#include <stdbool.h>
+#include <sys/ioctl.h>
+
+#include "peripheral_interface_uart.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+
+#define PATH_BUF_MAX 64
+#define UART_BUF_MAX 16
+
+#define UART_BAUDRATE_SIZE 19
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+#endif
+#define MAX_ERR_LEN 128
+
+char *sysfs_uart_path[] = {
+ "/dev/ttyS",
+ "/dev/ttyAMA",
+ "/dev/ttySAC",
+};
+
+static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = {
+ B0, B50, B75, B110, B134,
+ B150, B200, B300, B600, B1200,
+ B1800, B2400, B4800, B9600, B19200,
+ B38400, B57600, B115200, B230400
+};
+
+static const int byteinfo[4] = {CS5, CS6, CS7, CS8};
+
+int peripheral_interface_uart_close(peripheral_uart_h uart)
+{
+ int status;
+
+ _D("file_hndl : %d", uart->fd);
+
+ if (uart->fd < 0) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ status = peripheral_interface_uart_flush(uart);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg);
+ return -EIO;
+ }
+
+ status = close(uart->fd);
+ if (status < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_flush(peripheral_uart_h uart)
+{
+ int ret;
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ ret = tcflush(uart->fd, TCIOFLUSH);
+ if (ret < 0) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcflush failed, errmsg : %s", errmsg);
+ return -1;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud)
+{
+ int ret;
+ struct termios tio;
+
+ _D("file_hndl : %d, baud : %d", uart->fd, baud);
+
+ memset(&tio, 0, sizeof(tio));
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ if (baud > UART_BAUD_RATE_230400) {
+ _E("Invalid parameter");
+ return -EINVAL;
+ }
+
+ ret = tcgetattr(uart->fd, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcgetattr failed, errmsg : %s", errmsg);
+ return -1;
+ }
+ tio.c_cflag = peripheral_uart_br[baud];
+ tio.c_iflag = IGNPAR;
+ tio.c_oflag = 0;
+ tio.c_lflag = 0;
+ tio.c_cc[VMIN] = 1;
+ tio.c_cc[VTIME] = 0;
+
+ peripheral_interface_uart_flush(uart);
+ ret = tcsetattr(uart->fd, TCSANOW, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcsetattr failed, errmsg: %s", errmsg);
+ return -1;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits)
+{
+ int ret;
+ struct termios tio;
+
+ _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", uart->fd, byte_size, parity, stop_bits);
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ if (byte_size > UART_BYTE_SIZE_8BIT) {
+ _E("Invalid bytesize parameter");
+ return -EINVAL;
+ }
+
+ ret = tcgetattr(uart->fd, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcgetattr failed, errmsg: %s", errmsg);
+ return -1;
+ }
+
+ /* set byte size */
+ tio.c_cflag &= ~CSIZE;
+ tio.c_cflag |= byteinfo[byte_size];
+ tio.c_cflag |= (CLOCAL | CREAD);
+
+ /* set parity info */
+ switch (parity) {
+ case UART_PARITY_EVEN:
+ tio.c_cflag |= PARENB;
+ tio.c_cflag &= ~PARODD;
+ break;
+ case UART_PARITY_ODD:
+ tio.c_cflag |= PARENB;
+ tio.c_cflag |= PARODD;
+ break;
+ case UART_PARITY_NONE:
+ default:
+ tio.c_cflag &= ~PARENB;
+ tio.c_cflag &= ~PARODD;
+ break;
+ }
+
+ /* set stop bit */
+ switch (stop_bits) {
+ case UART_STOP_BITS_1BIT:
+ tio.c_cflag &= ~CSTOPB;
+ break;
+ case UART_STOP_BITS_2BIT:
+ tio.c_cflag |= CSTOPB;
+ break;
+ default:
+ _E("Invalid parameter stop_bits");
+ return -EINVAL;
+ }
+
+ peripheral_interface_uart_flush(uart);
+ ret = tcsetattr(uart->fd, TCSANOW, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcsetattr failed, errmsg : %s", errmsg);
+ return -1;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size)
+{
+ int ret;
+ struct termios tio;
+
+ _D("file_hndl : %d, bytesize : %d", uart->fd, byte_size);
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ if (byte_size > UART_BYTE_SIZE_8BIT) {
+ _E("Invalid bytesize parameter");
+ return -EINVAL;
+ }
+
+ ret = tcgetattr(uart->fd, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcgetattr failed, errmsg: %s", errmsg);
+ return -1;
+ }
+
+ /* set byte size */
+ tio.c_cflag &= ~CSIZE;
+ tio.c_cflag |= byteinfo[byte_size];
+ tio.c_cflag |= (CLOCAL | CREAD);
+
+ peripheral_interface_uart_flush(uart);
+ ret = tcsetattr(uart->fd, TCSANOW, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcsetattr failed, errmsg : %s", errmsg);
+ return -1;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_set_parity(peripheral_uart_h uart, uart_parity_e parity)
+{
+ int ret;
+ struct termios tio;
+
+ _D("file_hndl : %d, parity : %d", uart->fd, parity);
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ ret = tcgetattr(uart->fd, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcgetattr failed, errmsg: %s", errmsg);
+ return -1;
+ }
+
+ /* set parity info */
+ switch (parity) {
+ case UART_PARITY_EVEN:
+ tio.c_cflag |= PARENB;
+ tio.c_cflag &= ~PARODD;
+ break;
+ case UART_PARITY_ODD:
+ tio.c_cflag |= PARENB;
+ tio.c_cflag |= PARODD;
+ break;
+ case UART_PARITY_NONE:
+ default:
+ tio.c_cflag &= ~PARENB;
+ tio.c_cflag &= ~PARODD;
+ break;
+ }
+
+ peripheral_interface_uart_flush(uart);
+ ret = tcsetattr(uart->fd, TCSANOW, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcsetattr failed, errmsg : %s", errmsg);
+ return -1;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits)
+{
+ int ret;
+ struct termios tio;
+
+ _D("file_hndl : %d, stopbits : %d", uart->fd, stop_bits);
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ ret = tcgetattr(uart->fd, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcgetattr failed, errmsg: %s", errmsg);
+ return -1;
+ }
+
+ /* set stop bit */
+ switch (stop_bits) {
+ case UART_STOP_BITS_1BIT:
+ tio.c_cflag &= ~CSTOPB;
+ break;
+ case UART_STOP_BITS_2BIT:
+ tio.c_cflag |= CSTOPB;
+ break;
+ default:
+ _E("Invalid parameter stop_bits");
+ return -EINVAL;
+ }
+
+ peripheral_interface_uart_flush(uart);
+ ret = tcsetattr(uart->fd, TCSANOW, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcsetattr failed, errmsg : %s", errmsg);
+ return -1;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts)
+{
+ int ret;
+ struct termios tio;
+
+ _D("file_hndl : %d, xonxoff : %d, rtscts : %d", uart->fd, xonxoff, rtscts);
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ ret = tcgetattr(uart->fd, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcgetattr failed, errmsg : %s", errmsg);
+ return -1;
+ }
+
+ /* rtscts => 1: rts/cts on, 0: off */
+ if (rtscts)
+ tio.c_cflag |= CRTSCTS;
+ else
+ tio.c_cflag &= ~CRTSCTS;
+
+ /* xonxoff => 1: xon/xoff on, 0: off */
+ if (xonxoff)
+ tio.c_iflag |= (IXON | IXOFF | IXANY);
+ else
+ tio.c_iflag &= ~(IXON | IXOFF | IXANY);
+
+ ret = tcsetattr(uart->fd, TCSANOW, &tio);
+ if (ret) {
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("tcsetattr failed, errmsg : %s", errmsg);
+ return -1;
+ }
+
+ return 0;
+}
+
+int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length)
+{
+ int ret;
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ ret = read(uart->fd, (void *)buf, length);
+ if (ret <= 0) {
+ if (errno == EAGAIN)
+ return -EAGAIN;
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("read failed, errmsg : %s", errmsg);
+ return -EIO;
+ }
+
+ return ret;
+}
+
+int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length)
+{
+ int ret;
+
+ if (!uart->fd) {
+ _E("Invalid NULL parameter");
+ return -EINVAL;
+ }
+
+ ret = write(uart->fd, buf, length);
+ if (ret <= 0) {
+ if (errno == EAGAIN)
+ return -EAGAIN;
+ char errmsg[MAX_ERR_LEN];
+ strerror_r(errno, errmsg, MAX_ERR_LEN);
+ _E("write failed, errmsg : %s", errmsg);
+ return -EIO;
+ }
+
+ return ret;
+}
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdbool.h>
-
-#include "pwm.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-
-#define SYSFS_PWM_PATH "/sys/class/pwm"
-
-#define PATH_BUF_MAX 64
-#define PWM_BUF_MAX 16
-#define MAX_ERR_LEN 255
-
-int pwm_close(peripheral_pwm_h pwm)
-{
- int status;
-
- status = close(pwm->fd_period);
- if (status < 0) {
- _E("Error: pwm period fd close error \n");
- return -EIO;
- }
-
- status = close(pwm->fd_duty_cycle);
- if (status < 0) {
- _E("Error: pwm duty cycle fd close error \n");
- return -EIO;
- }
-
- status = close(pwm->fd_polarity);
- if (status < 0) {
- _E("Error: pwm polarity fd close error \n");
- return -EIO;
- }
-
- status = close(pwm->fd_enable);
- if (status < 0) {
- _E("Error: pwm enable fd close error \n");
- return -EIO;
- }
-
- return 0;
-}
-
-int pwm_set_period(peripheral_pwm_h pwm, int period)
-{
- int len, status;
- char pwm_buf[PWM_BUF_MAX] = {0};
-
- len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", period);
- status = write(pwm->fd_period, pwm_buf, len);
- if (status < 0) {
- _E("Failed to set period");
- return -EIO;
- }
-
- return 0;
-}
-
-int pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
-{
- int len, status;
- char pwm_buf[PWM_BUF_MAX] = {0};
-
- len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", duty_cycle);
- status = write(pwm->fd_duty_cycle, pwm_buf, len);
- if (status < 0) {
- _E("Failed to set duty cycle");
- return -EIO;
- }
-
- return 0;
-}
-
-int pwm_set_polarity(peripheral_pwm_h pwm, pwm_polarity_e polarity)
-{
- int status;
-
- if (polarity == PWM_POLARITY_NORMAL)
- status = write(pwm->fd_polarity, "normal", strlen("normal")+1);
- else if (polarity == PWM_POLARITY_INVERSED)
- status = write(pwm->fd_polarity, "inversed", strlen("inversed")+1);
- else {
- _E("Invalid pwm polarity : %d", polarity);
- return -EINVAL;
- }
-
- if (status <= 0) {
- _E("Failed to set polarity");
- return -EIO;
- }
-
- return 0;
-}
-
-int pwm_set_enable(peripheral_pwm_h pwm, bool enable)
-{
- int len, status;
- char pwm_buf[PWM_BUF_MAX] = {0};
-
- len = snprintf(pwm_buf, sizeof(pwm_buf), "%d", enable);
- status = write(pwm->fd_enable, pwm_buf, len);
- if (status < 0) {
- _E("Failed to set enable");
- return -EIO;
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/spi/spidev.h>
-
-#include "spi.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-
-#define SYSFS_SPI_DIR "/dev/spidev"
-#define SYSFS_SPI_BUFSIZ "/sys/module/spidev/parameters/bufsiz"
-#define SPI_BUFFER_MAX 64
-#define MAX_ERR_LEN 255
-
-int spi_close(peripheral_spi_h spi)
-{
- int status;
-
- _D("fd : %d", spi->fd);
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
-
- status = close(spi->fd);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to close fd : %d", spi->fd);
- return -EIO;
- }
-
- return 0;
-}
-
-int spi_set_mode(peripheral_spi_h spi, unsigned char mode)
-{
- int status;
-
- _D("fd : %d, mode : %d", spi->fd, mode);
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
-
- status = ioctl(spi->fd, SPI_IOC_WR_MODE, &mode);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to set mode(%d) : %s", mode, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int spi_set_bit_order(peripheral_spi_h spi, unsigned char lsb)
-{
- int status;
-
- _D("fd : %d, lsb : %d", spi->fd, lsb);
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
-
- status = ioctl(spi->fd, SPI_IOC_WR_LSB_FIRST, &lsb);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to set lsb first(%d), fd : %d, errmsg : %s", lsb, spi->fd, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits)
-{
- int status;
-
- _D("fd : %d, bits : %d", spi->fd, bits);
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
-
- status = ioctl(spi->fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to set bits(%d), fd : %d, errmsg : %s", bits, spi->fd, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int spi_set_frequency(peripheral_spi_h spi, unsigned int freq)
-{
- int status;
-
- _D("fd : %d, freq : %d", spi->fd, freq);
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd");
-
- status = ioctl(spi->fd, SPI_IOC_WR_MAX_SPEED_HZ, &freq);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to set frequency(%d), fd : %d, errmsg : %s", freq, spi->fd, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int spi_read(peripheral_spi_h spi, unsigned char *rxbuf, int length)
-{
- int status;
- struct spi_ioc_transfer xfer;
-
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd);
-
- memset(&xfer, 0, sizeof(struct spi_ioc_transfer));
- xfer.rx_buf = (unsigned long)rxbuf;
- xfer.len = length;
-
- status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to read data, fd : %d, length : %d, errmsg : %s", spi->fd, length, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int spi_write(peripheral_spi_h spi, unsigned char *txbuf, int length)
-{
- int status;
- struct spi_ioc_transfer xfer;
-
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd);
-
- memset(&xfer, 0, sizeof(struct spi_ioc_transfer));
- xfer.tx_buf = (unsigned long)txbuf;
- xfer.len = length;
-
- status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to write data(%d) : %s", length, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int spi_transfer(peripheral_spi_h spi, unsigned char *txbuf, unsigned char *rxbuf, int length)
-{
- int status;
- struct spi_ioc_transfer xfer;
-
- RETVM_IF(spi->fd < 0, -EINVAL, "Invalid fd : %d", spi->fd);
-
- if (!txbuf || !rxbuf || length < 0) return -EINVAL;
-
- memset(&xfer, 0, sizeof(xfer));
- xfer.tx_buf = (unsigned long)txbuf;
- xfer.rx_buf = (unsigned long)rxbuf;
- xfer.len = length;
-
- status = ioctl(spi->fd, SPI_IOC_MESSAGE(1), &xfer);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to exchange data(%d) : %s", length, errmsg);
- return -EIO;
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <termios.h>
-#include <stdbool.h>
-#include <sys/ioctl.h>
-
-#include "uart.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-
-#define PATH_BUF_MAX 64
-#define UART_BUF_MAX 16
-
-#define UART_BAUDRATE_SIZE 19
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-#endif
-#define MAX_ERR_LEN 128
-
-char *sysfs_uart_path[] = {
- "/dev/ttyS",
- "/dev/ttyAMA",
- "/dev/ttySAC",
-};
-
-static const int peripheral_uart_br[UART_BAUDRATE_SIZE] = {
- B0, B50, B75, B110, B134,
- B150, B200, B300, B600, B1200,
- B1800, B2400, B4800, B9600, B19200,
- B38400, B57600, B115200, B230400
-};
-
-static const int byteinfo[4] = {CS5, CS6, CS7, CS8};
-
-int uart_close(peripheral_uart_h uart)
-{
- int status;
-
- _D("file_hndl : %d", uart->fd);
-
- if (uart->fd < 0) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- status = uart_flush(uart);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg);
- return -EIO;
- }
-
- status = close(uart->fd);
- if (status < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("Failed to close fd : %d, errmsg : %s", uart->fd, errmsg);
- return -EIO;
- }
-
- return 0;
-}
-
-int uart_flush(peripheral_uart_h uart)
-{
- int ret;
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- ret = tcflush(uart->fd, TCIOFLUSH);
- if (ret < 0) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcflush failed, errmsg : %s", errmsg);
- return -1;
- }
-
- return 0;
-}
-
-int uart_set_baud_rate(peripheral_uart_h uart, uart_baud_rate_e baud)
-{
- int ret;
- struct termios tio;
-
- _D("file_hndl : %d, baud : %d", uart->fd, baud);
-
- memset(&tio, 0, sizeof(tio));
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- if (baud > UART_BAUD_RATE_230400) {
- _E("Invalid parameter");
- return -EINVAL;
- }
-
- ret = tcgetattr(uart->fd, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcgetattr failed, errmsg : %s", errmsg);
- return -1;
- }
- tio.c_cflag = peripheral_uart_br[baud];
- tio.c_iflag = IGNPAR;
- tio.c_oflag = 0;
- tio.c_lflag = 0;
- tio.c_cc[VMIN] = 1;
- tio.c_cc[VTIME] = 0;
-
- uart_flush(uart);
- ret = tcsetattr(uart->fd, TCSANOW, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcsetattr failed, errmsg: %s", errmsg);
- return -1;
- }
-
- return 0;
-}
-
-int uart_set_mode(peripheral_uart_h uart, uart_byte_size_e byte_size, uart_parity_e parity, uart_stop_bits_e stop_bits)
-{
- int ret;
- struct termios tio;
-
- _D("file_hndl : %d, bytesize : %d, parity : %d, stopbits : %d", uart->fd, byte_size, parity, stop_bits);
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- if (byte_size > UART_BYTE_SIZE_8BIT) {
- _E("Invalid bytesize parameter");
- return -EINVAL;
- }
-
- ret = tcgetattr(uart->fd, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcgetattr failed, errmsg: %s", errmsg);
- return -1;
- }
-
- /* set byte size */
- tio.c_cflag &= ~CSIZE;
- tio.c_cflag |= byteinfo[byte_size];
- tio.c_cflag |= (CLOCAL | CREAD);
-
- /* set parity info */
- switch (parity) {
- case UART_PARITY_EVEN:
- tio.c_cflag |= PARENB;
- tio.c_cflag &= ~PARODD;
- break;
- case UART_PARITY_ODD:
- tio.c_cflag |= PARENB;
- tio.c_cflag |= PARODD;
- break;
- case UART_PARITY_NONE:
- default:
- tio.c_cflag &= ~PARENB;
- tio.c_cflag &= ~PARODD;
- break;
- }
-
- /* set stop bit */
- switch (stop_bits) {
- case UART_STOP_BITS_1BIT:
- tio.c_cflag &= ~CSTOPB;
- break;
- case UART_STOP_BITS_2BIT:
- tio.c_cflag |= CSTOPB;
- break;
- default:
- _E("Invalid parameter stop_bits");
- return -EINVAL;
- }
-
- uart_flush(uart);
- ret = tcsetattr(uart->fd, TCSANOW, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcsetattr failed, errmsg : %s", errmsg);
- return -1;
- }
-
- return 0;
-}
-
-int uart_set_byte_size(peripheral_uart_h uart, uart_byte_size_e byte_size)
-{
- int ret;
- struct termios tio;
-
- _D("file_hndl : %d, bytesize : %d", uart->fd, byte_size);
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- if (byte_size > UART_BYTE_SIZE_8BIT) {
- _E("Invalid bytesize parameter");
- return -EINVAL;
- }
-
- ret = tcgetattr(uart->fd, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcgetattr failed, errmsg: %s", errmsg);
- return -1;
- }
-
- /* set byte size */
- tio.c_cflag &= ~CSIZE;
- tio.c_cflag |= byteinfo[byte_size];
- tio.c_cflag |= (CLOCAL | CREAD);
-
- uart_flush(uart);
- ret = tcsetattr(uart->fd, TCSANOW, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcsetattr failed, errmsg : %s", errmsg);
- return -1;
- }
-
- return 0;
-}
-
-int uart_set_parity(peripheral_uart_h uart, uart_parity_e parity)
-{
- int ret;
- struct termios tio;
-
- _D("file_hndl : %d, parity : %d", uart->fd, parity);
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- ret = tcgetattr(uart->fd, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcgetattr failed, errmsg: %s", errmsg);
- return -1;
- }
-
- /* set parity info */
- switch (parity) {
- case UART_PARITY_EVEN:
- tio.c_cflag |= PARENB;
- tio.c_cflag &= ~PARODD;
- break;
- case UART_PARITY_ODD:
- tio.c_cflag |= PARENB;
- tio.c_cflag |= PARODD;
- break;
- case UART_PARITY_NONE:
- default:
- tio.c_cflag &= ~PARENB;
- tio.c_cflag &= ~PARODD;
- break;
- }
-
- uart_flush(uart);
- ret = tcsetattr(uart->fd, TCSANOW, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcsetattr failed, errmsg : %s", errmsg);
- return -1;
- }
-
- return 0;
-}
-
-int uart_set_stop_bits(peripheral_uart_h uart, uart_stop_bits_e stop_bits)
-{
- int ret;
- struct termios tio;
-
- _D("file_hndl : %d, stopbits : %d", uart->fd, stop_bits);
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- ret = tcgetattr(uart->fd, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcgetattr failed, errmsg: %s", errmsg);
- return -1;
- }
-
- /* set stop bit */
- switch (stop_bits) {
- case UART_STOP_BITS_1BIT:
- tio.c_cflag &= ~CSTOPB;
- break;
- case UART_STOP_BITS_2BIT:
- tio.c_cflag |= CSTOPB;
- break;
- default:
- _E("Invalid parameter stop_bits");
- return -EINVAL;
- }
-
- uart_flush(uart);
- ret = tcsetattr(uart->fd, TCSANOW, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcsetattr failed, errmsg : %s", errmsg);
- return -1;
- }
-
- return 0;
-}
-
-int uart_set_flow_control(peripheral_uart_h uart, bool xonxoff, bool rtscts)
-{
- int ret;
- struct termios tio;
-
- _D("file_hndl : %d, xonxoff : %d, rtscts : %d", uart->fd, xonxoff, rtscts);
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- ret = tcgetattr(uart->fd, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcgetattr failed, errmsg : %s", errmsg);
- return -1;
- }
-
- /* rtscts => 1: rts/cts on, 0: off */
- if (rtscts)
- tio.c_cflag |= CRTSCTS;
- else
- tio.c_cflag &= ~CRTSCTS;
-
- /* xonxoff => 1: xon/xoff on, 0: off */
- if (xonxoff)
- tio.c_iflag |= (IXON | IXOFF | IXANY);
- else
- tio.c_iflag &= ~(IXON | IXOFF | IXANY);
-
- ret = tcsetattr(uart->fd, TCSANOW, &tio);
- if (ret) {
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("tcsetattr failed, errmsg : %s", errmsg);
- return -1;
- }
-
- return 0;
-}
-
-int uart_read(peripheral_uart_h uart, uint8_t *buf, unsigned int length)
-{
- int ret;
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- ret = read(uart->fd, (void *)buf, length);
- if (ret <= 0) {
- if (errno == EAGAIN)
- return -EAGAIN;
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("read failed, errmsg : %s", errmsg);
- return -EIO;
- }
-
- return ret;
-}
-
-int uart_write(peripheral_uart_h uart, uint8_t *buf, unsigned int length)
-{
- int ret;
-
- if (!uart->fd) {
- _E("Invalid NULL parameter");
- return -EINVAL;
- }
-
- ret = write(uart->fd, buf, length);
- if (ret <= 0) {
- if (errno == EAGAIN)
- return -EAGAIN;
- char errmsg[MAX_ERR_LEN];
- strerror_r(errno, errmsg, MAX_ERR_LEN);
- _E("write failed, errmsg : %s", errmsg);
- return -EIO;
- }
-
- return ret;
-}