| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /*****************************************************************************
- * Copyright (c) 2019, Nations Technologies Inc.
- *
- * All rights reserved.
- * ****************************************************************************
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the disclaimer below.
- *
- * Nations' name may not be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
- * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * ****************************************************************************/
- /**
- * @file pin.h
- * @author Nations
- * @version v1.0.0
- *
- * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
- */
- #ifndef PIN_H__
- #define PIN_H__
- #include <rtthread.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /* pin device and operations for RT-Thread */
- struct rt_device_pin
- {
- struct rt_device parent;
- const struct rt_pin_ops *ops;
- };
- #define PIN_LOW 0x00
- #define PIN_HIGH 0x01
- #define PIN_MODE_OUTPUT 0x00
- #define PIN_MODE_INPUT 0x01
- #define PIN_MODE_INPUT_PULLUP 0x02
- #define PIN_MODE_INPUT_PULLDOWN 0x03
- #define PIN_MODE_OUTPUT_OD 0x04
- #define PIN_IRQ_MODE_RISING 0x00
- #define PIN_IRQ_MODE_FALLING 0x01
- #define PIN_IRQ_MODE_RISING_FALLING 0x02
- #define PIN_IRQ_MODE_HIGH_LEVEL 0x03
- #define PIN_IRQ_MODE_LOW_LEVEL 0x04
- #define PIN_IRQ_DISABLE 0x00
- #define PIN_IRQ_ENABLE 0x01
- #define PIN_IRQ_PIN_NONE -1
- struct rt_device_pin_mode
- {
- rt_uint16_t pin;
- rt_uint16_t mode;
- };
- struct rt_device_pin_status
- {
- rt_uint16_t pin;
- rt_uint16_t status;
- };
- struct rt_pin_irq_hdr
- {
- rt_int16_t pin;
- rt_uint16_t mode;
- void (*hdr)(void *args);
- void *args;
- };
- struct rt_pin_ops
- {
- void (*pin_mode)(struct rt_device *device, rt_base_t pin, rt_base_t mode);
- void (*pin_write)(struct rt_device *device, rt_base_t pin, rt_base_t value);
- int (*pin_read)(struct rt_device *device, rt_base_t pin);
- /* TODO: add GPIO interrupt */
- rt_err_t (*pin_attach_irq)(struct rt_device *device, rt_int32_t pin,
- rt_uint32_t mode, void (*hdr)(void *args), void *args);
- rt_err_t (*pin_detach_irq)(struct rt_device *device, rt_int32_t pin);
- rt_err_t (*pin_irq_enable)(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled);
- };
- int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data);
- void rt_pin_mode(rt_base_t pin, rt_base_t mode);
- void rt_pin_write(rt_base_t pin, rt_base_t value);
- int rt_pin_read(rt_base_t pin);
- rt_err_t rt_pin_attach_irq(rt_int32_t pin, rt_uint32_t mode,
- void (*hdr)(void *args), void *args);
- rt_err_t rt_pin_detach_irq(rt_int32_t pin);
- rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint32_t enabled);
- #ifdef __cplusplus
- }
- #endif
- #endif
|