Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:870a29ad1074, committed 2016-01-24
- Comitter:
- sk398
- Date:
- Sun Jan 24 14:39:33 2016 +0000
- Child:
- 1:6557cf755742
- Commit message:
- Working edition. Basic and inefficient however;
Changed in this revision
| SD20.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SD20.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SD20.cpp Sun Jan 24 14:39:33 2016 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "SD20.h"
+
+SD20::SD20(I2C *bus,int I2CAddress, int BusHz)
+{
+ _bus = bus;
+ deviceAddress = I2CAddress;
+ BusHz = BusHz;
+ _bus -> frequency(BusHz);
+}
+
+int SD20::UpdatePWM(char *DataOutput)
+{
+ if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN))
+ {
+ printf("I2C Failed to write\r\n");
+ return 1;
+ }
+ else
+ {
+ printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput);
+ return 0;
+ }
+}
+
+int SD20::StartStopPWM(int Channel,bool Start)
+{
+ if(Start == CHANNEL_START)
+ {
+ int DataOutput[] = {Channel,0x01};
+ if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN))
+ {
+ printf("I2C Failed to write\r\n");
+ return 1;
+ }
+ else
+ {
+ printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput);
+ return 0;
+ }
+ }
+ else
+ {
+ int DataOutput[] = {Channel,0x00};
+ if(_bus -> write(deviceAddress,(char*)DataOutput,OUT_BUF_LEN))
+ {
+ printf("I2C Failed to write\r\n");
+ return 1;
+ }
+ else
+ {
+ printf("0x%02x sent to Reg: 0x%02x\r\n",*(DataOutput+1),*DataOutput);
+ return 0;
+ }
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SD20.h Sun Jan 24 14:39:33 2016 +0000
@@ -0,0 +1,77 @@
+#ifndef SD20_H
+#define SD20_H
+
+/* SD20 Internal Register Map */
+#define SOFTWARE_REVISION_REG 0x00
+#define SERVO_1_REG 0x01
+#define SERVO_2_REG 0x02
+#define SERVO_3_REG 0x03
+#define SERVO_4_REG 0x04
+#define SERVO_5_REG 0x05
+#define SERVO_6_REG 0x06
+#define SERVO_7_REG 0x07
+#define SERVO_8_REG 0x08
+#define SERVO_9_REG 0x09
+#define SERVO_10_REG 0x10
+#define SERVO_11_REG 0x11
+#define SERVO_12_REG 0x12
+#define SERVO_13_REG 0x13
+#define SERVO_14_REG 0x14
+#define SERVO_15_REG 0x15
+#define SERVO_16_REG 0x16
+#define SERVO_17_REG 0x17
+#define SERVO_18_REG 0x18
+#define SERVO_19_REG 0x19
+#define SERVO_20_REG 0x20
+#define STD_ETD_MODE_CTRL 0x21
+#define ETD_MODE_OFST_HIGH 0x22
+#define ETD_MODE_OFST_LOW 0x23
+
+// Output Buffer Length
+#define OUT_BUF_LEN 2
+
+#define CHANNEL_STOP 0
+#define CHANNEL_START 1
+
+class SD20
+{
+
+private:
+
+ int deviceAddress;
+ int BusHz;
+ I2C *_bus;
+ int OutputData();
+ char OutputBuffer[OUT_BUF_LEN];
+
+public:
+
+ /** Create a SD20 Constructor, connected over I2C Master connection
+ *
+ * parameter bus: I2C object
+ * parameter BusHz: I2C Bus Frequency
+ */
+ SD20(I2C *bus,int I2CAddress, int BusHz);
+
+ /**
+ * Start/Stop PWM output on specificed channel (Standard mode)
+ *
+ * parameter Channel: Servo Channel to be stopped
+ * parameter Start: Select whether to start[1] or stop [0] a given channel
+ * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1]
+ * where print commands are skipped to save operational time
+ */
+ int StartStopPWM(int Channel, bool Start);
+
+ /**
+ * Update PWM output on specificed channel (Standard mode)
+ *
+ * parameter DataOutput: Structured as follows: [Servo Channel[1:20], Pulse Width[0x00:0xFF]]
+ * parameter mode: Select whether debug mode[0] and prints result or implementation mode [1]
+ * where print commands are skipped to save operational time
+ */
+ int UpdatePWM(char *DataOutput);
+
+};
+
+#endif
\ No newline at end of file