-
Notifications
You must be signed in to change notification settings - Fork 0
/
blink.c
85 lines (65 loc) · 1.88 KB
/
blink.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*++
Morse Encoder Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
Author:
Axel Rietschin - June 27, 2020
Environment:
ESP32 with ESP-IDF 4.x
--*/
#include <stdio.h>
#include <ctype.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "MorseEncoder.h"
// Can use project configuration menu (idf.py menuconfig) to choose
// the GPIO to blink and the base time unit, or you can edit the
// following lines and define values here.
//
// A good base time unit is 100ms. The pin depends on the hardware
// configuration. The Huzzah32 ESP32 board has the LED wired on pin 13.
//
#define BASE_TIME_UNIT_MS CONFIG_BASE_TIME_UNIT_MS // or use 100
#define BLINK_GPIO CONFIG_BLINK_GPIO // or use your pin #
//
// Environment-dependent functions supplied to the Morse encoder
//
inline int
MorseEncoder_GetBaseTimeUnitMs()
{
return BASE_TIME_UNIT_MS;
}
void
MorseEncoder_SetSignalState(int state, int pauseDurationMs)
{
gpio_set_level(BLINK_GPIO, state ? 1 : 0);
if (pauseDurationMs > 0)
{
vTaskDelay(pauseDurationMs / portTICK_PERIOD_MS);
}
}
//
// Sample program
//
void
Initialize()
{
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
gpio_set_level(BLINK_GPIO, 0);
}
void
app_main()
{
Initialize();
while (1)
{
MorseEncoder_TransmitStartOfMessageSymbol();
MorseEncoder_TransmitString("HI, MY NAME IS AXEL. I JUST WROTE A MORSE ENCODER :-)");
MorseEncoder_TransmitEndOfMessageSymbol();
}
}