Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embedded-systems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
James Immanuel Magsino
embedded-systems
Commits
01640785
Commit
01640785
authored
4 months ago
by
jamesimmanuel.magsino@stud.h-da.de
Browse files
Options
Downloads
Patches
Plain Diff
Glorious functioning code
parent
af12d888
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.c
+24
-30
24 additions, 30 deletions
src/main.c
with
24 additions
and
30 deletions
src/main.c
+
24
−
30
View file @
01640785
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#include
<unistd.h>
#include
<unistd.h>
#include
<hardware/pwm.h>
#include
<hardware/pwm.h>
const
uint8_t
init
[
4
]
=
{
0x21
,
0xa0
,
0xe
1
,
0x81
};
const
uint8_t
init
[
4
]
=
{
0x21
,
0xa0
,
0xe
f
,
0x81
};
const
uint8_t
zeile
[
8
]
=
{
0x00
,
0x02
,
0x04
,
0x06
,
0x08
,
0x10
,
0x12
,
0x14
};
const
uint8_t
zeile
[
8
]
=
{
0x00
,
0x02
,
0x04
,
0x06
,
0x08
,
0x10
,
0x12
,
0x14
};
const
uint8_t
fill
[
17
]
=
{
0x00
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
};
const
uint8_t
fill
[
17
]
=
{
0x00
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
};
...
@@ -125,9 +125,14 @@ void callback(uint gpio, uint32_t events)
...
@@ -125,9 +125,14 @@ void callback(uint gpio, uint32_t events)
if
(
events
&
GPIO_IRQ_EDGE_FALL
)
if
(
events
&
GPIO_IRQ_EDGE_FALL
)
{
{
volatile
uint16_t
duration
=
pwm_get_counter
(
slice_num
)
*
42
;
volatile
uint16_t
test
=
pwm_get_counter
(
slice_num
);
volatile
uint16_t
duration
=
pwm_get_counter
(
slice_num
);
volatile
float
distance
=
(
test
*
314
)
/
(
20000
);
volatile
float
distance
=
(
duration
*
340
)
/
(
20000
);
if
(
distance
<=
2
)
{
distance
=
0
;
}
if
(
distance
>
20
)
if
(
distance
>
20
)
{
{
distance
=
20
;
distance
=
20
;
...
@@ -144,34 +149,27 @@ void callback(uint gpio, uint32_t events)
...
@@ -144,34 +149,27 @@ void callback(uint gpio, uint32_t events)
{
{
pwm_set_counter
(
slice_num
,
0
);
pwm_set_counter
(
slice_num
,
0
);
}
}
// volatile uint16_t test = pwm_get_counter(another_slice_num);
// volatile float distance = (test * 314) / (20000);
// if (distance > 20)
// {
// distance = 20;
// }
// distance = 20 - distance;
// volatile int percentage = (distance / 10) * 100;
// set_progress(percentage);
// pwm_set_counter(another_slice_num, 0);
}
}
void
init_pwm
()
void
init_pwm
()
{
{
gpio_init
(
28
);
gpio_set_dir
(
28
,
GPIO_OUT
);
gpio_set_function
(
28
,
GPIO_FUNC_PWM
);
gpio_set_function
(
28
,
GPIO_FUNC_PWM
);
volatile
uint
slice_num
=
pwm_gpio_to_slice_num
(
28
);
volatile
uint
slice_num
=
pwm_gpio_to_slice_num
(
28
);
pwm_set_clkdiv
(
slice_num
,
125
);
pwm_set_clkdiv
(
slice_num
,
125
);
//
pwm_set_wrap
(
slice_num
,
0xFFFF
);
pwm_set_wrap
(
slice_num
,
0xFFFF
);
pwm_set_chan_level
(
slice_num
,
PWM_CHAN_A
,
10
);
pwm_set_chan_level
(
slice_num
,
PWM_CHAN_A
,
10
);
pwm_set_enabled
(
slice_num
,
true
);
pwm_set_enabled
(
slice_num
,
true
);
}
}
void
pwm_echo_init
()
void
pwm_echo_init
()
{
{
gpio_init
(
27
);
gpio_set_dir
(
27
,
GPIO_IN
);
volatile
uint
slice_num
=
pwm_gpio_to_slice_num
(
27
);
volatile
uint
slice_num
=
pwm_gpio_to_slice_num
(
27
);
/*
/*
// Count once for every 100 cycles the PWM B input is high
// Count once for every 100 cycles the PWM B input is high
...
@@ -183,17 +181,17 @@ void pwm_echo_init()
...
@@ -183,17 +181,17 @@ void pwm_echo_init()
*/
*/
// count once for every 42 cycles the PWM B input is high
// count once for every 42 cycles the PWM B input is high
// one cycle approximately equal to 20 ms
// one cycle approximately equal to 20 ms
pwm_set_clkdiv
(
slice_num
,
42
);
pwm_set_clkdiv
(
slice_num
,
125
);
pwm_set_wrap
(
slice_num
,
0xFFFF
);
pwm_set_wrap
(
slice_num
,
0xFFFF
);
pwm_set_clkdiv_mode
(
slice_num
,
PWM_DIV_
B_HIGH
);
pwm_set_clkdiv_mode
(
slice_num
,
PWM_DIV_
FREE_RUNNING
);
pwm_set_enabled
(
slice_num
,
true
);
pwm_set_enabled
(
slice_num
,
true
);
}
}
int
a
=
0
;
int
a
=
0
;
int
main
()
int
main
()
{
{
// clock enable: 100000 baud (bit/s)
// clock enable: 100
.
000 baud (bit/s)
i2c_init
(
i2c_default
,
100000
);
i2c_init
(
i2c_default
,
100000
0
);
// Pin 0 and 1 are given I2C functionality (they're the ones connected to the led matrix)
// Pin 0 and 1 are given I2C functionality (they're the ones connected to the led matrix)
gpio_set_function
(
0
,
GPIO_FUNC_I2C
);
gpio_set_function
(
0
,
GPIO_FUNC_I2C
);
gpio_set_function
(
1
,
GPIO_FUNC_I2C
);
gpio_set_function
(
1
,
GPIO_FUNC_I2C
);
...
@@ -212,18 +210,11 @@ int main()
...
@@ -212,18 +210,11 @@ int main()
i2c_write_blocking
(
i2c_default
,
0x70
,
&
init
[
2
],
1
,
false
);
i2c_write_blocking
(
i2c_default
,
0x70
,
&
init
[
2
],
1
,
false
);
i2c_write_blocking
(
i2c_default
,
0x70
,
&
init
[
3
],
1
,
false
);
i2c_write_blocking
(
i2c_default
,
0x70
,
&
init
[
3
],
1
,
false
);
i2c_write_blocking
(
i2c_default
,
0x70
,
zeile
,
4
,
false
);
i2c_write_blocking
(
i2c_default
,
0x70
,
empty
,
17
,
false
);
init_pwm
();
init_pwm
();
pwm_echo_init
();
pwm_echo_init
();
gpio_set_irq_enabled_with_callback
(
27
,
GPIO_IRQ_EDGE_FALL
|
GPIO_IRQ_EDGE_RISE
,
true
,
&
callback
);
gpio_set_irq_enabled_with_callback
(
27
,
GPIO_IRQ_EDGE_FALL
|
GPIO_IRQ_EDGE_RISE
,
true
,
callback
);
while
(
1
)
{
}
/*
/*
timer_hw->dbgpause = 0;
timer_hw->dbgpause = 0;
gpio_init(27);
gpio_init(27);
...
@@ -257,6 +248,9 @@ int main()
...
@@ -257,6 +248,9 @@ int main()
asm("BKPT #0");
asm("BKPT #0");
}
}
*/
*/
while
(
1
)
{
}
a
=
3
;
a
=
3
;
return
0
;
return
0
;
}
}
\ No newline at end of file
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