C8051F32x firmware infrastructure
Sign in or create your account | Project List | Help
C8051F32x firmware infrastructure Git Source Tree
Root/
| 1 | /* |
| 2 | * f32x/gpio-s3c24xx.h - Really primitive S3C244x GPIO access. Ports B-H only. |
| 3 | * |
| 4 | * Written 2008 by Werner Almesberger |
| 5 | * Copyright 2008 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * Ports are numbered 0 = A, 1 = B, ... |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GPIO_S3C24XX_H |
| 19 | #define GPIO_S3C24XX_H |
| 20 | |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | |
| 24 | |
| 25 | volatile uint32_t *mem; |
| 26 | |
| 27 | |
| 28 | #define port_dat(port) mem[port*4+1] |
| 29 | #define port_con(port) mem[port*4] |
| 30 | |
| 31 | |
| 32 | static inline void gpio_high(unsigned port, unsigned bit) |
| 33 | { |
| 34 | port_dat(port) |= 1 << bit; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | static inline void gpio_low(unsigned port, unsigned bit) |
| 39 | { |
| 40 | port_dat(port) &= ~(1 << bit); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | static inline void gpio_set(unsigned port, unsigned bit, int value) |
| 45 | { |
| 46 | if (value) |
| 47 | gpio_high(port, bit); |
| 48 | else |
| 49 | gpio_low(port, bit); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | static inline int gpio_get(unsigned port, unsigned bit) |
| 54 | { |
| 55 | return (port_dat(port) >> bit) & 1; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | static inline void gpio_output(unsigned port, unsigned bit) |
| 60 | { |
| 61 | port_con(port) = (port_con(port) & ~(3 << bit*2)) | (1 << bit*2); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | static inline void gpio_input(unsigned port, unsigned bit) |
| 66 | { |
| 67 | port_con(port) &= ~(3 << bit*2); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | void gpio_init(void); |
| 72 | |
| 73 | |
| 74 | #endif /* !GPIO_S3C24XX_H */ |
| 75 |
Branches:
master
