Revision 0:8e3468376286, committed 2011-05-07
- Comitter:
- faker
- Date:
- Sat May 07 12:37:10 2011 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r 8e3468376286 Distotion_Unit.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Distotion_Unit.cpp Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,42 @@
+/*****************************************************/
+/* Distotion_Unit.cpp */
+/* */
+/*****************************************************/
+
+#define DIST_MAIN
+#include "Distotion_Unit.h"
+
+#define LIMIT_P (32767)
+#define LIMIT_N (-32768)
+
+int distotion(int iEffectIn) {
+
+ int iSignal;
+
+ // Input Gain
+ iSignal = iEffectIn * g_inputGain;
+
+ // Clip
+ switch(g_distMode){
+ case 1: if (iSignal < 0)iSignal *= (-1);
+ if (iSignal >= g_clipLevel)iSignal = g_clipLevel;
+ break;
+ case 2: if (iSignal >= g_clipLevel)iSignal = g_clipLevel;
+ if (iSignal <= -g_clipLevel)iSignal = -g_clipLevel;
+ break;
+ case 3: if (iSignal >= g_clipLevel)iSignal = g_clipLevel;
+ if (iSignal <= (-g_clipLevel / 2))iSignal = (-g_clipLevel / 2);
+ break;
+ default:break;
+ }
+
+ // Output Gain
+ iSignal *= g_outputGain;
+ if (iSignal >= LIMIT_P)iSignal = LIMIT_P;
+ if (iSignal <= LIMIT_N)iSignal = LIMIT_N;
+
+ return iSignal;
+
+}
+
+#undef DIST_MAIN
\ No newline at end of file
diff -r 000000000000 -r 8e3468376286 Distotion_Unit.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Distotion_Unit.h Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,48 @@
+/*****************************************************/
+/* Distotion_Unit.h */
+/* */
+/*****************************************************/
+
+#ifndef _DISTOTIN_UNIT_INCLUDE
+#define _DISTOTIN_UNIT_INCLUDE
+
+#undef EXTERN
+#ifdef DIST_MAIN
+#define EXTERN
+#else
+#define EXTERN extern
+#endif
+
+// Gloval Valinat
+
+EXTERN float g_inputGain
+#ifdef DIST_MAIN
+ = 1.0
+#endif
+ ;
+
+EXTERN int g_clipLevel
+#ifdef DIST_MAIN
+ = 15000
+#endif
+ ;
+
+EXTERN float g_outputGain
+#ifdef DIST_MAIN
+ = 1.0
+#endif
+ ;
+
+EXTERN char g_distMode
+#ifdef DIST_MAIN
+ = 1;
+#endif
+ ;
+
+
+// Function
+
+EXTERN int distotion(int);
+
+#undef EXTERN
+#endif
\ No newline at end of file
diff -r 000000000000 -r 8e3468376286 R_Sw_Check.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/R_Sw_Check.cpp Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,69 @@
+/*****************************************************/
+/* Rotary Switch Check.cpp */
+/* */
+/* */
+/*****************************************************/
+
+#define SW_CHECK_MAIN
+#include "R_Sw_Check.h"
+
+unsigned char ucRotarySwPol(char swA_0, char swB_0,
+ char swA_1, char swB_1,
+ char swA_2, char swB_2,
+ char swA_3, char swB_3,
+ int *pol){
+
+ unsigned char ucRet = 0xFF;
+
+// Rotary SW0
+ *pol = 0;
+ if((swA_0 == 0) && (g_sw0_0 == 1) && (swB_0 == 1)){
+ *pol = -1;
+ ucRet = 0;
+ }
+ if((swA_0 == 1) && (g_sw0_0 == 0) && (swB_0 == 1)){
+ *pol = 1;
+ ucRet = 0;
+ }
+ g_sw0_0 = swA_0;
+
+// Rotary SW1
+ *(pol+1) = 0;
+ if((swA_1 == 0) && (g_sw1_0 == 1) && (swB_1 == 1)){
+ *(pol+1) = -1;
+ ucRet = 1;
+ }
+ if((swA_1 == 1) && (g_sw1_0 == 0) && (swB_1 == 1)){
+ *(pol+1) = 1;
+ ucRet = 1;
+ }
+ g_sw1_0 = swA_1;
+
+// Rotary SW2
+ *(pol+2) = 0;
+ if((swA_2 == 0) && (g_sw2_0 == 1) && (swB_2 == 1)){
+ *(pol+2) = -1;
+ ucRet = 2;
+ }
+ if((swA_2 == 1) && (g_sw2_0 == 0) && (swB_2 == 1)){
+ *(pol+2) = 1;
+ ucRet = 2;
+ }
+ g_sw2_0 = swA_2;
+
+// Rotary SW3
+ *(pol+3) = 0;
+ if((swA_3 == 0) && (g_sw3_0 == 1) && (swB_3 == 1)){
+ *(pol+3) = -1;
+ ucRet = 3;
+ }
+ if((swA_3 == 1) && (g_sw3_0 == 0) && (swB_3 == 1)){
+ *(pol+3) = 1;
+ ucRet = 3;
+ }
+ g_sw3_0 = swA_3;
+
+ return ucRet;
+}
+
+#undef SW_CHECK_MAIN
\ No newline at end of file
diff -r 000000000000 -r 8e3468376286 R_Sw_Check.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/R_Sw_Check.h Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,31 @@
+/*****************************************************/
+/* Rotary Switch Check.h */
+/* */
+/* */
+/*****************************************************/
+
+#ifndef _SW_CHECK_INCLUDE
+#define _SW_CHECK_INCLUDE
+
+#undef EXTERN
+#ifdef SW_CHECK_MAIN
+#define EXTERN
+#else
+#define EXTERN extern
+#endif
+
+// Gloval Valinat
+
+EXTERN char
+#ifdef SW_CHECK_MAIN
+ g_sw0_0 = 1, g_sw1_0 = 1, g_sw2_0 = 1, g_sw3_0 = 1;
+#else
+ g_sw0_0, g_sw1_0, g_sw2_0, g_sw3_0;
+#endif
+
+// Function
+
+EXTERN unsigned char ucRotarySwPol(char, char, char, char, char, char, char, char, int*);
+
+#undef EXTERN
+#endif
\ No newline at end of file
diff -r 000000000000 -r 8e3468376286 TextLCD.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.cpp Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,180 @@
+/* draft mbed TextLCD
+ * (c) 2007/8, sford
+ */
+
+#include "TextLCD.h"
+
+#include "mbed.h"
+
+using namespace mbed;
+
+/*
+ * useful info found at http://www.a-netz.de/lcd.en.php
+ *
+ *
+ * Initialisation
+ * ==============
+ *
+ * After attaching the supply voltage/after a reset, the display needs to be brought in to a defined state
+ *
+ * - wait approximately 15 ms so the display is ready to execute commands
+ * - Execute the command 0x30 ("Display Settings") three times (wait 1,64ms after each command, the busy flag cannot be queried now).
+ * - The display is in 8 bit mode, so if you have only connected 4 data pins you should only transmit the higher nibble of each command.
+ * - If you want to use the 4 bit mode, now you can execute the command to switch over to this mode now.
+ * - Execute the "clear display" command
+ *
+ * Timing
+ * ======
+ *
+ * Nearly all commands transmitted to the display need 40us for execution.
+ * Exceptions are the commands "Clear Display and Reset" and "Set Cursor to Start Position"
+ * These commands need 1.64ms for execution. These timings are valid for all displays working with an
+ * internal clock of 250kHz. But I do not know any displays that use other frequencies. Any time you
+ * can use the busy flag to test if the display is ready to accept the next command.
+ *
+ * _e is kept high apart from calling clock
+ * _rw is kept 0 (write) apart from actions that uyse it differently
+ * _rs is set by the data/command writes
+ */
+
+TextLCD::TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1,
+ PinName d2, PinName d3) : _rw(rw), _rs(rs),
+ _e(e), _d(d0, d1, d2, d3){
+
+ _rows = 4;
+ _columns = 20;
+
+ _rw = 0;
+ _e = 1;
+ _rs = 0; // command mode
+
+ // Should theoretically wait 15ms, but most things will be powered up pre-reset
+ // so i'll disable that for the minute. If implemented, could wait 15ms post reset
+ // instead
+ // wait(0.015);
+
+ // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+ for(int i=0; i<3; i++) {
+ writeNibble(0x3);
+ wait(0.00164); // this command takes 1.64ms, so wait for it
+ }
+ writeNibble(0x2); // 4-bit mode
+
+ writeCommand(0x28); // Function set 001 BW N F - -
+ writeCommand(0x0C);
+ writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+
+ cls();
+}
+
+int TextLCD::_putc(int value) {
+ if(value == '\n') {
+ newline();
+ } else {
+ writeData(value);
+ }
+ return value;
+}
+
+int TextLCD::_getc() {
+ return 0;
+}
+
+void TextLCD::newline() {
+ _column = 0;
+ _row++;
+ if(_row >= _rows) {
+ _row = 0;
+ }
+ locate(_column, _row);
+}
+
+void TextLCD::locate(int column, int row) {
+ if(column < 0 || column >= _columns || row < 0 || row >= _rows) {
+ error("locate(%d,%d) out of range on %dx%d display", column, row, _columns, _rows);
+ return;
+ }
+
+ _row = row;
+ _column = column;
+ int address=0;
+ // row 0 : 0x0->0x13
+ // row 1 : 0x40->0x53
+ // row 2 : 0x14->0x27
+ // row 3 : 0x54->0x67
+
+ switch (_row) {
+ case (0) : address = 0x00 + _column;
+ break;
+ case (1) : address = 0x40 + _column;
+ break;
+ case (2) : address = 0x14 + _column;
+ break;
+ case (3) : address = 0x54 + _column;
+ break;
+ }
+
+ address += 0x80;
+
+// }
+// else {
+ // memory starts at 0x80, and is 40 chars long per row
+// address = 0x80 + (_row * 40) + _column;
+// }
+
+ writeCommand(address);
+}
+
+
+void TextLCD::rows(int rows) {
+ _rows = rows;
+}
+
+
+void TextLCD::columns(int columns) {
+ _columns = columns;
+}
+
+
+
+
+void TextLCD::cls() {
+ writeCommand(0x01); // Clear Display
+ wait(0.00164f); // This command takes 1.64 ms
+ locate(0, 0);
+}
+
+void TextLCD::reset() {
+ cls();
+}
+
+void TextLCD::clock() {
+ wait(0.000040f);
+ _e = 0;
+ wait(0.000040f); // most instructions take 40us
+ _e = 1;
+}
+
+void TextLCD::writeNibble(int value) {
+ _d = value;
+ clock();
+}
+
+void TextLCD::writeByte(int value) {
+ writeNibble(value >> 4);
+ writeNibble(value >> 0);
+}
+
+void TextLCD::writeCommand(int command) {
+ _rs = 0;
+ writeByte(command);
+}
+
+void TextLCD::writeData(int data) {
+ _rs = 1;
+ writeByte(data);
+ _column++;
+ if(_column >= _columns) {
+ newline();
+ }
+}
diff -r 000000000000 -r 8e3468376286 TextLCD.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.h Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,51 @@
+/* draft mbed TextLCD
+ * (c) 2007/8, sford
+ */
+
+#ifndef MBED_TEXTLCD_H
+#define MBED_TEXTLCD_H
+
+#include "Stream.h"
+#include "DigitalOut.h"
+#include "BusOut.h"
+#include "mbed.h"
+
+namespace mbed {
+
+class TextLCD : public Stream {
+
+public:
+
+ TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1,
+ PinName d2, PinName d3);
+
+ void rows(int rows);
+ void columns(int columns);
+
+ virtual void locate(int row, int column);
+ virtual void cls();
+ virtual void reset();
+
+protected:
+
+ void clock();
+ void writeData(int data);
+ void writeCommand(int command);
+ void writeByte(int value);
+ void writeNibble(int value);
+ virtual int _putc(int c);
+ virtual int _getc();
+ virtual void newline();
+
+ int _rows;
+ int _columns;
+ int _row;
+ int _column;
+ DigitalOut _rw, _rs, _e;
+ BusOut _d;
+
+};
+
+}
+
+#endif
diff -r 000000000000 -r 8e3468376286 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,149 @@
+/*****************************************************/
+/* MBED MULTI EFFECTOR */
+/* */
+/* */
+/*****************************************************/
+
+#include "mbed.h"
+#include "TextLCD.h"
+#include "R_Sw_Check.h"
+#include "Distotion_Unit.h"
+
+Ticker sampling;
+AnalogIn Ain(p17);
+AnalogOut Aout(p18);
+TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3)
+DigitalIn Rsw0A(p5);
+DigitalIn Rsw0B(p6);
+DigitalIn Rsw1A(p7);
+DigitalIn Rsw1B(p8);
+DigitalIn Rsw2A(p9);
+DigitalIn Rsw2B(p10);
+DigitalIn Rsw3A(p11);
+DigitalIn Rsw3B(p12);
+
+/*******************************/
+/* For Test Signal */
+/*******************************/
+#define TEST_SIGNAL_ENABLE (0) // 1 : Internal SinWave for Debug
+#define TEST_SIGNAL_FREQ (1000.0) // Frequency [Hz]
+#define TEST_SIGNAL_AMP (30000.0) // Amplitude
+#define PAI (3.14159)
+
+/*******************************/
+/* For ADC & DAC Setting */
+/*******************************/
+#define SAMPLING_TIME (25.0) // ADC Sampling Rate [us]
+
+volatile unsigned int *g_usiAd0cr, *g_usiAd0dr2; // ADC Reg
+unsigned int *g_usiDacr; // DAC Reg
+unsigned int g_usiFinalOut;
+int g_ssBuff[10];
+float g_fTestWaveT;
+
+/*******************************/
+/* Effect Process */
+/*******************************/
+void effectProcess() {
+ // Line Out
+ *g_usiDacr = g_usiFinalOut;
+ // ADC Start
+ *g_usiAd0cr = 0x01200204;
+
+#if (TEST_SIGNAL_ENABLE == 1) // Test Signal Sin Wave
+ g_ssBuff[0] = TEST_SIGNAL_AMP * sin(g_fTestWaveT);
+ g_fTestWaveT = g_fTestWaveT + 2.0 * PAI * SAMPLING_TIME * TEST_SIGNAL_FREQ / 1e6;
+ if (g_fTestWaveT >= (2.0 * PAI))g_fTestWaveT = 0;
+#endif
+
+ //
+ // Effect Func();
+ //
+
+ g_ssBuff[1] = distotion(g_ssBuff[0]);
+
+ //
+ // Effect Func();
+ //
+
+#if (TEST_SIGNAL_ENABLE == 0)
+ while (1) {
+ if ((*g_usiAd0dr2 & 0x80000000) != 0)break; // ADC Done ?
+ }
+ g_ssBuff[0] = (int)(*g_usiAd0dr2 & 0x0000FFF0) - 32768;
+#endif
+
+ g_usiFinalOut = 0x00010000 | (g_ssBuff[1] + 32768);
+}
+
+
+/*******************************/
+/* MAIN */
+/*******************************/
+int main() {
+
+ int iParamSwPol[4];
+
+ // LCD INIT
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Dist Mode Type %d", g_distMode);
+ lcd.locate(0,1);
+ lcd.printf("Input Gain %4.1f", g_inputGain);
+ lcd.locate(0,2);
+ lcd.printf("Clip Level %6d", g_clipLevel);
+ lcd.locate(0,3);
+ lcd.printf("Output Gain %4.1f", g_outputGain);
+
+ // ADC & DAC SETTING
+ g_usiAd0cr = (unsigned int*)0x40034000;
+ g_usiAd0dr2 = (unsigned int*)0x40034018;
+ g_usiDacr = (unsigned int*)0x4008C000;
+
+ // SAMPLING TIMER START
+ sampling.attach_us(&effectProcess, SAMPLING_TIME);
+
+
+ while (1) {
+
+ //
+ // Parameter Setting Func
+ //
+
+ switch(ucRotarySwPol(Rsw0A, Rsw0B, Rsw1A, Rsw1B, Rsw2A, Rsw2B, Rsw3A, Rsw3B, iParamSwPol)){
+ case 0: g_distMode = g_distMode + iParamSwPol[0];
+ if(g_distMode <= 0)g_distMode = 3;
+ if(g_distMode > 3)g_distMode = 1;
+ lcd.locate(0,0);
+ lcd.printf(" ");
+ lcd.locate(0,0);
+ lcd.printf("Dist Mode Type %d", g_distMode);
+ break;
+ case 1: g_inputGain = g_inputGain + 0.5 * iParamSwPol[1];
+ lcd.locate(0,1);
+ lcd.printf(" ");
+ lcd.locate(0,1);
+ lcd.printf("Input Gain %4.1f", g_inputGain);
+ break;
+ case 2: g_clipLevel = g_clipLevel + 1000 * iParamSwPol[2];
+ lcd.locate(0,2);
+ lcd.printf(" ");
+ lcd.locate(0,2);
+ lcd.printf("Clip Level %6d", g_clipLevel);
+ break;
+ case 3: g_outputGain = g_outputGain + 0.5 * iParamSwPol[3];
+ lcd.locate(0,3);
+ lcd.printf(" ");
+ lcd.locate(0,3);
+ lcd.printf("Output Gain %4.1f", g_outputGain);
+ break;
+ default:break;
+ }
+
+ //
+ // Parameter Setting Func
+ //
+
+ }
+}
+
diff -r 000000000000 -r 8e3468376286 mbed.bld
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld Sat May 07 12:37:10 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e