Skip to content

Instantly share code, notes, and snippets.

@ColorfulCodes
Created May 13, 2020 03:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ColorfulCodes/131462942e0973df099da6b08d010d8a to your computer and use it in GitHub Desktop.
Save ColorfulCodes/131462942e0973df099da6b08d010d8a to your computer and use it in GitHub Desktop.
This is the mt3620 blinky
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <applibs/storage.h>
#include <applibs/log.h>
#include <applibs/gpio.h>
int Storage_OpenMutableFile(void);
int main(void)
{
// This minimal Azure Sphere app repeatedly toggles GPIO 9, which is the green channel of RGB
// LED 1 on the MT3620 RDB.
// If your device exposes different GPIOs, you might need to change this value. For example,
// to run the app on a Seeed mini-dev kit, change the GPIO from 9 to 7 in the call to
// GPIO_OpenAsOutput and in the app_manifest.json to blink its LED. Check with your hardware
// manufacturer to determine which GPIOs are available.
// Use this app to test that device and SDK installation succeeded that you can build,
// deploy, and debug an app with Visual Studio, and that you can deploy an app over the air,
// per the instructions here: https://docs.microsoft.com/azure-sphere/quickstarts/qs-overview
//
// It is NOT recommended to use this as a starting point for developing apps; instead use
// the extensible samples here: https://github.com/Azure/azure-sphere-samples
Log_Debug(
"\nVisit https://github.com/Azure/azure-sphere-samples for extensible samples to use as a "
"starting point for full applications.\n");
// Change this GPIO number and the number in app_manifest.json if required by your hardware.
//GPIO_OutputMode_PushPull means
//Low turns LED on, High turns off
int fd = GPIO_OpenAsInput(12);
if (fd < 0) {
Log_Debug(
"Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
strerror(errno), errno);
return -1;
}
int fd2 = GPIO_OpenAsOutput(10, GPIO_OutputMode_PushPull, GPIO_Value_High);
if (fd2 < 0) {
Log_Debug(
"Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
strerror(errno), errno);
return -1;
}
int fd3 = GPIO_OpenAsOutput(16, GPIO_OutputMode_PushPull, GPIO_Value_High);
if (fd3 < 0) {
Log_Debug(
"Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
strerror(errno), errno);
return -1;
}
const struct timespec sleepTime = {1, 0};
while (true) {
GPIO_SetValue(fd, GPIO_Value_Low);
GPIO_SetValue(fd2, GPIO_Value_Low);
GPIO_SetValue(fd3, GPIO_Value_Low);
nanosleep(&sleepTime, NULL);
GPIO_SetValue(fd, GPIO_Value_High);
GPIO_SetValue(fd2, GPIO_Value_High);
GPIO_SetValue(fd3, GPIO_Value_High);
nanosleep(&sleepTime, NULL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment