Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
multipass
Commits
136d16ad
Commit
136d16ad
authored
6 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Extend ESP8266 GPIO
parent
17a7c6d3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/esp8266/driver/gpio.h
+12
-0
12 additions, 0 deletions
include/esp8266/driver/gpio.h
src/arch/esp8266/driver/gpio.cc
+125
-3
125 additions, 3 deletions
src/arch/esp8266/driver/gpio.cc
with
137 additions
and
3 deletions
include/esp8266/driver/gpio.h
+
12
−
0
View file @
136d16ad
...
...
@@ -7,10 +7,22 @@ class GPIO {
public:
GPIO
()
{}
enum
Pin
:
unsigned
char
{
d3
=
0
,
tx
,
d4
,
rx
,
d2
,
d1
,
d6
=
12
,
d7
,
d5
,
d8
,
d0
=
16
};
void
setup
();
void
led_on
(
unsigned
char
id
);
void
led_off
(
unsigned
char
id
);
void
led_toggle
(
unsigned
char
id
);
void
input
(
unsigned
char
const
pin
);
void
input
(
unsigned
char
const
pin
,
bool
pullup
);
void
output
(
unsigned
char
const
pin
);
unsigned
char
read
(
unsigned
char
const
pin
);
void
write
(
unsigned
char
const
pin
,
unsigned
char
value
);
};
extern
GPIO
gpio
;
...
...
This diff is collapsed.
Click to expand it.
src/arch/esp8266/driver/gpio.cc
+
125
−
3
View file @
136d16ad
...
...
@@ -22,7 +22,7 @@ void ICACHE_FLASH_ATTR GPIO::setup()
#endif
}
void
ICACHE_FLASH_ATTR
GPIO
::
led_on
(
unsigned
char
id
)
void
ICACHE_FLASH_ATTR
GPIO
::
led_on
(
unsigned
char
const
id
)
{
#ifdef LED_ON_GPIO16
if
(
id
==
0
)
{
...
...
@@ -35,7 +35,7 @@ void ICACHE_FLASH_ATTR GPIO::led_on(unsigned char id)
#endif
}
void
ICACHE_FLASH_ATTR
GPIO
::
led_off
(
unsigned
char
id
)
void
ICACHE_FLASH_ATTR
GPIO
::
led_off
(
unsigned
char
const
id
)
{
#ifdef LED_ON_GPIO16
if
(
id
==
0
)
{
...
...
@@ -48,7 +48,7 @@ void ICACHE_FLASH_ATTR GPIO::led_off(unsigned char id)
#endif
}
void
ICACHE_FLASH_ATTR
GPIO
::
led_toggle
(
unsigned
char
id
)
void
ICACHE_FLASH_ATTR
GPIO
::
led_toggle
(
unsigned
char
const
id
)
{
#ifdef LED_ON_GPIO16
if
(
id
==
0
)
{
...
...
@@ -69,4 +69,126 @@ void ICACHE_FLASH_ATTR GPIO::led_toggle(unsigned char id)
#endif
}
void
ICACHE_FLASH_ATTR
GPIO
::
input
(
unsigned
char
const
pin
)
{
if
(
pin
==
d0
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO0_U
,
FUNC_GPIO0
);
}
else
if
(
pin
==
tx
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_U0TXD_U
,
FUNC_GPIO1
);
}
else
if
(
pin
==
d4
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO2_U
,
FUNC_GPIO2
);
}
else
if
(
pin
==
rx
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_U0RXD_U
,
FUNC_GPIO3
);
}
else
if
(
pin
==
d2
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO4_U
,
FUNC_GPIO4
);
}
else
if
(
pin
==
d1
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO5_U
,
FUNC_GPIO5
);
}
else
if
(
pin
==
d6
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTDI_U
,
FUNC_GPIO12
);
}
else
if
(
pin
==
d7
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTCK_U
,
FUNC_GPIO13
);
}
else
if
(
pin
==
d5
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTMS_U
,
FUNC_GPIO14
);
}
else
if
(
pin
==
d8
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTDO_U
,
FUNC_GPIO15
);
}
else
if
(
pin
==
d0
)
{
// TODO this sets it as output, not input
WRITE_PERI_REG
(
PAD_XPD_DCDC_CONF
,
(
READ_PERI_REG
(
PAD_XPD_DCDC_CONF
)
&
0xffffffbc
)
|
(
uint32
)
0x1
);
WRITE_PERI_REG
(
RTC_GPIO_CONF
,
(
READ_PERI_REG
(
RTC_GPIO_CONF
)
&
(
uint32
)
0xfffffffe
)
|
(
uint32
)
0x0
);
WRITE_PERI_REG
(
RTC_GPIO_ENABLE
,
(
READ_PERI_REG
(
RTC_GPIO_ENABLE
)
&
(
uint32
)
0xfffffffe
)
|
(
uint32
)
0x1
);
}
if
(
pin
<
d0
)
{
gpio_output_set
(
0
,
0
,
0
,
(
1
<<
pin
));
}
}
void
ICACHE_FLASH_ATTR
GPIO
::
input
(
unsigned
char
const
pin
,
bool
pullup
)
{
if
(
pin
==
d0
)
{
if
(
pullup
)
{
PIN_PULLUP_EN
(
PERIPHS_IO_MUX_GPIO0_U
);
}
else
{
PIN_PULLUP_DIS
(
PERIPHS_IO_MUX_GPIO0_U
);
}
}
else
if
(
pin
==
tx
)
{
if
(
pullup
)
{
PIN_PULLUP_EN
(
PERIPHS_IO_MUX_U0TXD_U
);
}
else
{
PIN_PULLUP_DIS
(
PERIPHS_IO_MUX_U0TXD_U
);
}
}
else
if
(
pin
==
d4
)
{
if
(
pullup
)
{
PIN_PULLUP_EN
(
PERIPHS_IO_MUX_GPIO2_U
);
}
else
{
PIN_PULLUP_DIS
(
PERIPHS_IO_MUX_GPIO2_U
);
}
}
else
if
(
pin
==
rx
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_U0RXD_U
,
FUNC_GPIO3
);
}
else
if
(
pin
==
d2
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO4_U
,
FUNC_GPIO4
);
}
else
if
(
pin
==
d1
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO5_U
,
FUNC_GPIO5
);
}
else
if
(
pin
==
d6
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTDI_U
,
FUNC_GPIO12
);
}
else
if
(
pin
==
d7
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTCK_U
,
FUNC_GPIO13
);
}
else
if
(
pin
==
d5
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTMS_U
,
FUNC_GPIO14
);
}
else
if
(
pin
==
d8
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTDO_U
,
FUNC_GPIO15
);
}
else
if
(
pin
==
d0
)
{
// TODO this sets it as output, not input
WRITE_PERI_REG
(
PAD_XPD_DCDC_CONF
,
(
READ_PERI_REG
(
PAD_XPD_DCDC_CONF
)
&
0xffffffbc
)
|
(
uint32
)
0x1
);
WRITE_PERI_REG
(
RTC_GPIO_CONF
,
(
READ_PERI_REG
(
RTC_GPIO_CONF
)
&
(
uint32
)
0xfffffffe
)
|
(
uint32
)
0x0
);
WRITE_PERI_REG
(
RTC_GPIO_ENABLE
,
(
READ_PERI_REG
(
RTC_GPIO_ENABLE
)
&
(
uint32
)
0xfffffffe
)
|
(
uint32
)
0x1
);
}
input
(
pin
);
}
void
ICACHE_FLASH_ATTR
GPIO
::
output
(
unsigned
char
const
pin
)
{
if
(
pin
==
d0
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO0_U
,
FUNC_GPIO0
);
}
else
if
(
pin
==
tx
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_U0TXD_U
,
FUNC_GPIO1
);
}
else
if
(
pin
==
d4
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO2_U
,
FUNC_GPIO2
);
}
else
if
(
pin
==
rx
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_U0RXD_U
,
FUNC_GPIO3
);
}
else
if
(
pin
==
d2
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO4_U
,
FUNC_GPIO4
);
}
else
if
(
pin
==
d1
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_GPIO5_U
,
FUNC_GPIO5
);
}
else
if
(
pin
==
d6
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTDI_U
,
FUNC_GPIO12
);
}
else
if
(
pin
==
d7
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTCK_U
,
FUNC_GPIO13
);
}
else
if
(
pin
==
d5
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTMS_U
,
FUNC_GPIO14
);
}
else
if
(
pin
==
d8
)
{
PIN_FUNC_SELECT
(
PERIPHS_IO_MUX_MTDO_U
,
FUNC_GPIO15
);
}
else
if
(
pin
==
d0
)
{
WRITE_PERI_REG
(
PAD_XPD_DCDC_CONF
,
(
READ_PERI_REG
(
PAD_XPD_DCDC_CONF
)
&
0xffffffbc
)
|
(
uint32
)
0x1
);
WRITE_PERI_REG
(
RTC_GPIO_CONF
,
(
READ_PERI_REG
(
RTC_GPIO_CONF
)
&
(
uint32
)
0xfffffffe
)
|
(
uint32
)
0x0
);
WRITE_PERI_REG
(
RTC_GPIO_ENABLE
,
(
READ_PERI_REG
(
RTC_GPIO_ENABLE
)
&
(
uint32
)
0xfffffffe
)
|
(
uint32
)
0x1
);
}
if
(
pin
<
d0
)
{
gpio_output_set
(
0
,
0
,
(
1
<<
pin
),
0
);
}
}
unsigned
char
ICACHE_FLASH_ATTR
GPIO
::
read
(
unsigned
char
const
pin
)
{
return
(
gpio_input_get
()
&
(
1
<<
pin
));
}
void
ICACHE_FLASH_ATTR
GPIO
::
write
(
unsigned
char
const
pin
,
unsigned
char
value
)
{
if
(
value
)
{
gpio_output_set
(
1
<<
pin
,
0
,
0
,
0
);
}
else
{
gpio_output_set
(
0
,
1
<<
pin
,
0
,
0
);
}
}
GPIO
gpio
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment