Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "clickmodules"]
path = clickmodules
url = https://github.com/Avnet/clickmodules.git
13 changes: 11 additions & 2 deletions AvnetStarterKitReferenceDesign.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.572
# Visual Studio Version 16
VisualStudioVersion = 16.0.29306.81
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AvnetStarterKitReferenceDesign", "AvnetStarterKitReferenceDesign\AvnetStarterKitReferenceDesign.vcxproj", "{1EC4AAF4-4A6F-46C8-B538-4F4B9DA1238B}"
ProjectSection(ProjectDependencies) = postProject
{8A4B3C2D-3514-4F81-8E6A-A869DE31EC07} = {8A4B3C2D-3514-4F81-8E6A-A869DE31EC07}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ClickLib", "ClickLib\ClickLib.vcxproj", "{8A4B3C2D-3514-4F81-8E6A-A869DE31EC07}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +20,10 @@ Global
{1EC4AAF4-4A6F-46C8-B538-4F4B9DA1238B}.Debug|ARM.Build.0 = Debug|ARM
{1EC4AAF4-4A6F-46C8-B538-4F4B9DA1238B}.Release|ARM.ActiveCfg = Release|ARM
{1EC4AAF4-4A6F-46C8-B538-4F4B9DA1238B}.Release|ARM.Build.0 = Release|ARM
{8A4B3C2D-3514-4F81-8E6A-A869DE31EC07}.Debug|ARM.ActiveCfg = Debug|ARM
{8A4B3C2D-3514-4F81-8E6A-A869DE31EC07}.Debug|ARM.Build.0 = Debug|ARM
{8A4B3C2D-3514-4F81-8E6A-A869DE31EC07}.Release|ARM.ActiveCfg = Release|ARM
{8A4B3C2D-3514-4F81-8E6A-A869DE31EC07}.Release|ARM.Build.0 = Release|ARM
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>-Werror=implicit-function-declaration %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">..\clickmodules\RELAY;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<LibraryDependencies>applibs;pthread;gcc_s;c;azureiot</LibraryDependencies>
<LibraryDependencies>applibs;pthread;gcc_s;c;azureiot;ClickLib</LibraryDependencies>
<AdditionalOptions>-Wl,--no-undefined -nodefaultlibs %(AdditionalOptions)</AdditionalOptions>
<AdditionalLibraryDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">..\ClickLib\bin\ARM\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
</Project>
2 changes: 1 addition & 1 deletion AvnetStarterKitReferenceDesign/app_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"AllowedConnections": [],
"AllowedTcpServerPorts": [],
"AllowedUdpServerPorts": [],
"Gpio": [ 0, 4, 5, 8, 9, 10, 12, 13, 34 ],
"Gpio": [ 0, 4, 5, 8, 9, 10, 12, 13, 34, 1, 35 ],
"Uart": [],
"I2cMaster": [ "ISU2" ],
"SpiMaster": [],
Expand Down
3 changes: 3 additions & 0 deletions AvnetStarterKitReferenceDesign/build_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// If your application is going to connect straight to a IoT Hub, then enable this define.
//#define IOT_HUB_APPLICATION

// include relay click module
//#define RELAY_CLICK

#if (defined(IOT_CENTRAL_APPLICATION) && defined(IOT_HUB_APPLICATION))
#error "Can not define both IoT Central and IoT Hub Applications at the same time only define one."
#endif
Expand Down
64 changes: 64 additions & 0 deletions AvnetStarterKitReferenceDesign/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,42 @@
#include <applibs/wificonfig.h>
#include <azureiot/iothub_device_client_ll.h>

#if (defined(RELAY_CLICK))
// relay click section

#include "relay.h"

#define MIKROE_PWM MT3620_GPIO1 //click#1=GPIO0; click#2=GPIO1
#define MIKROE_CS MT3620_GPIO35 //click#1=GPIO34; click#2=GPIO35

static int r1PinFd; //relay #1
static GPIO_Value_Type relay1Pin;
static int r2PinFd; //relay #2
static GPIO_Value_Type relay2Pin;

void init(void)
{
r1PinFd = GPIO_OpenAsOutput(MIKROE_PWM, relay1Pin, GPIO_Value_Low);
r2PinFd = GPIO_OpenAsOutput(MIKROE_CS, relay2Pin, GPIO_Value_Low);
}

void state(RELAY* ptr)
{
if (ptr->relay1_status == 1)
GPIO_SetValue(r1PinFd, GPIO_Value_High);
else
GPIO_SetValue(r1PinFd, GPIO_Value_Low);

if (ptr->relay2_status == 1)
GPIO_SetValue(r2PinFd, GPIO_Value_High);
else
GPIO_SetValue(r2PinFd, GPIO_Value_Low);
}

// relay click section
#endif


// Provide local access to variables in other files
extern twin_t twinArray[];
extern int twinArraySize;
Expand Down Expand Up @@ -492,6 +528,15 @@ int main(int argc, char *argv[])
// Clear the ssid array
memset(ssid, 0, 128);

#if (defined(RELAY_CLICK))
int i;
RELAY* rptr;

rptr = open_relay(state, init);
sleep(1);
i = 0;
#endif

Log_Debug("Version String: %s\n", argv[1]);
Log_Debug("Avnet Starter Kit Simple Reference Application starting.\n");
if (InitPeripheralsAndHandlers() != 0) {
Expand All @@ -500,6 +545,17 @@ int main(int argc, char *argv[])

// Use epoll to wait for events and trigger handlers, until an error or SIGTERM happens
while (!terminationRequired) {

#if (defined(RELAY_CLICK))
relaystate(rptr, (i & 1) ? relay1_set : relay1_clr);
relaystate(rptr, (i & 2) ? relay2_set : relay2_clr);
Log_Debug("(%d) relay2 %s, relay1 %s\n", i,
relaystate(rptr, relay2_rd) ? "ON" : "OFF",
relaystate(rptr, relay1_rd) ? "ON" : "OFF");
sleep(10);
++i;
#endif

if (WaitForEventAndCallHandler(epollFd) != 0) {
terminationRequired = true;
}
Expand Down Expand Up @@ -559,6 +615,14 @@ int main(int argc, char *argv[])
#endif
}

#if (defined(RELAY_CLICK))
close_relay(rptr);
GPIO_SetValue(r1PinFd, GPIO_Value_Low);
GPIO_SetValue(r2PinFd, GPIO_Value_Low);
Log_Debug("relay2 OFF, relay1 oFF\nDONE...\n");
#endif


ClosePeripheralsAndHandlers();
Log_Debug("Application exiting.\n");
return 0;
Expand Down
56 changes: 56 additions & 0 deletions ClickLib/ClickLib.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\clickmodules\RELAY\relay.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\clickmodules\RELAY\relay.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8a4b3c2d-3514-4f81-8e6a-a869de31ec07}</ProjectGuid>
<Keyword>AzureSphere</Keyword>
<RootNamespace>ClickLib</RootNamespace>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
<ApplicationType>Linux</ApplicationType>
<ApplicationTypeRevision>1.0</ApplicationTypeRevision>
<TargetLinuxPlatform>Generic</TargetLinuxPlatform>
<LinuxProjectType>{D51BCBC9-82E9-4017-911E-C93873C4EA2B}</LinuxProjectType>
<DebugMachineType>Device</DebugMachineType>
<PlatformToolset>GCC_AzureSphere_1_0</PlatformToolset>
<ProjectPublicIncludePath>$(MSBuildProjectDirectory)\Inc\Public</ProjectPublicIncludePath>
<PublicIncludePath>$(MSBuildProjectDirectory)\Inc\Public</PublicIncludePath>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
<TargetSysroot>1</TargetSysroot>
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<TargetSysroot>1</TargetSysroot>
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="Shared" />
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>-Werror=implicit-function-declaration %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
27 changes: 27 additions & 0 deletions ClickLib/ClickLib.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\clickmodules\RELAY\relay.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\clickmodules\RELAY\relay.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions clickmodules
Submodule clickmodules added at 083235