Kunimasa Noda / Mbed 2 deprecated lpc812_mlx90620

Dependencies:   MLX90620 mbed

Files at this revision

API Documentation at this revision

Comitter:
kunipm9
Date:
Fri Apr 04 14:01:24 2014 +0000
Commit message:
1st

Changed in this revision

MLX90620.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
xprintf.c Show annotated file Show diff for this revision Revisions of this file
xprintf.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MLX90620.lib	Fri Apr 04 14:01:24 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/loopsva/code/MLX90620/#a86b8d0294ee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 04 14:01:24 2014 +0000
@@ -0,0 +1,213 @@
+#include "mbed.h"
+#include "MLX90620.h"
+
+extern "C" { 
+  void xsprintf (char* buff, const char* fmt, ...);
+}
+
+#define BS          0x08                    //ascii backspace
+#define CR          0x0d                    //ascii CR
+#define LF          0x0a                    //ascii LF
+#define SP          0x20                    //ascii space
+#define ESC         0x1b                    //ascii escape
+#define DP          0x2e                    //ascii decimal point / period
+#define ticC        0x03                    //ascii control C
+#define ticX        0x18                    //ascii control X
+
+extern "C" void mbed_reset();
+int revision = 102;
+int gDebug = 2;
+
+//RawSerial pc (USBTX, USBRX);
+Serial pc(USBTX, USBRX);
+//UART1 PIO0_0  PIO0_4
+//UART2 PIO0_1/USBRX  PIO0_6/USBTX
+
+//I2C i2c1(P0_10, P0_11);
+MLX90620 mlx(P0_10, P0_11, "mlx");            //MLX90620 register access
+
+//RN-42 Reset
+DigitalOut p1(P0_8);
+
+//MLX90620 buffers used by MLX90620.cpp
+char* EEbuf = new char[256];
+char* RamCmmd = new char[8];                //holds / sends MLX90620 RAM commands
+char* RamBuf = new char[128];               //0x3f words, values are 'unsigned short'
+
+//For MLX90620
+unsigned short ConfigReg = 0;               //MLX90620 configuration register
+float Ta = 0.0;
+double TempPxl = 0;
+
+//Used for display of temperature and extreme values
+int pixX = 0;                               //display pixel X (0-15)
+int pixY = 0;                               //display pixel Y (0-3)
+
+//Display Options
+int TempC = 'C';                            //***USED BY .INI FILE  display temperatures in degrees C or F
+
+//--------------------------------------------------------------------------------------------------------------------------------------//
+//Detect I2C device chain
+
+int i2cQty = 16;                            //number of bytes to get
+char i2cData[32];                           //i2c buffer data
+
+char buf[256];
+
+//--------------------------------------------------------------------------------------------------------------------------------------//
+// Display on PC using VT100 escape codes
+int loop = 0;
+bool GotAmbient = false;
+bool ReFrame = false;                       //do a reframe if asked
+
+int ShowTempsColor()
+{
+    ConfigReg = mlx.GetConfigReg();
+    if(GotAmbient == false) {
+        if((ConfigReg & 0x0100) == 0) {
+            Ta = mlx.GetDieTemp();
+            GotAmbient = true;
+        } else {
+            return(ConfigReg & 0x0100);
+        }
+    }
+    if((ConfigReg & 0x0200) == 0) {
+        loop++;
+        GotAmbient = false;
+        if(ReFrame == true) {
+            ReFrame = false;
+        }
+        mlx.LoadMLXRam();
+        mlx.StartMeasurement();
+    }
+    return(0);
+}
+
+void ShowTempsVT100()
+{
+    double HoldTemp = TempPxl;
+    pc.puts("st\r\n");
+    for(pixY = 0; pixY <= 3; pixY++) {
+        for(pixX = 0; pixX < 64; pixX = pixX + 4) {
+            TempPxl = mlx.CalcPixel(pixX + pixY);
+            if ((TempC == 'c') || (TempC == 'C')) {
+                HoldTemp = TempPxl;
+            } else {
+                HoldTemp = TempPxl * 9.0 / 5.0 + 32.0;
+            }
+
+//            if(HoldTemp >= 100.0) {
+//                pc.printf(" %.1f  ", HoldTemp);
+//            } else if((HoldTemp <= 10.0) && (HoldTemp >= 0.0)) {
+//                pc.printf("  %.2f  ", HoldTemp);
+//            } else if((HoldTemp >= -10.0) && (HoldTemp < 0.0)) {
+//                pc.printf(" %.2f  ", HoldTemp);
+//            } else if(HoldTemp < -10.0) {
+//                pc.printf("%.2f  ", HoldTemp);
+//            } else {
+//                pc.printf(" %.2f  ", HoldTemp);
+//            }
+            int temp = HoldTemp * 100;
+            xsprintf(buf, "%d\r\n", temp);
+            pc.puts(buf);
+            xsprintf(buf, "info x:%d  y:%d  %d\r\n", pixX, pixY, temp);
+            pc.puts(buf);
+        }
+//        pc.printf("\r\n", ESC, pixY);
+    }
+    pc.puts("ex\r\n");
+}
+
+//--------------------------------------------------------------------------------------------------------------------------------------//
+// Display Pixels in color
+
+//--------------------------------------------------------------------------------------------------------------------------------------//
+
+int main(void)
+{
+    // RN-42
+    p1 = 0;
+    wait_ms(300);
+
+    LPC_SYSCON->BODCTRL |= 2;
+    LPC_SYSCON->PDRUNCFG &= (0<<3);
+
+    p1 = 1;
+    wait_ms(100);
+    pc.baud(115200);
+
+    int initFail = 0;
+    //load up eeprom into buffer
+    if((mlx.LoadEEPROM())) {
+        pc.puts("err e1\r\n");
+        initFail++;
+    }
+
+    for(pixY = 0; pixY <= 3; pixY++) {
+        for(pixX = 0; pixX < 64; pixX = pixX + 4) {
+            int Pixel = pixY + pixX;
+            if (EEbuf[Pixel + 0x80] < 100) {
+                EEbuf[Pixel + 0x80] = 100;
+            }
+        }
+    }
+
+    //Init MLX90620
+    unsigned short x = 0;
+    if((mlx.SetOscTrimReg())) {
+        pc.puts("er e2\r\n");
+        initFail++;
+    } else {
+        x = mlx.GetOscTrimReg();
+        xsprintf(buf, "info Osc:  0x%04x\r\n", x);
+        pc.puts(buf);
+    }
+
+    if((mlx.SetConfigReg())) {
+        pc.puts("err e3\r\n");
+        initFail++;
+    } else {
+        x = mlx.GetConfigReg();
+        xsprintf(buf, "info Config: 0x%04x\r\n", x);
+        pc.puts(buf);
+        x = mlx.GetPTATReg();
+        xsprintf(buf, "info PTAT:   0x%04x\r\n", x);
+        pc.puts(buf);
+    }
+
+    if((mlx.StartMeasurement())) {
+        pc.puts("err e4\r\n");
+        initFail++;
+    }
+    wait_ms(300);
+
+    if(initFail == 0) {
+        mlx.CalcTa_To();
+        Ta = mlx.GetDieTemp();
+        xsprintf(buf, "info Ta = %f\n\n", Ta);
+        pc.puts(buf);
+    } else {
+        pc.puts("err e5\r\n");
+    }
+    ShowTempsColor();
+
+    while (true) {
+        if(!(ShowTempsColor())) {
+            do {
+                wait_ms(1);
+            } while(ShowTempsColor() != 0);
+        }
+        
+        for(pixY = 0; pixY <= 3; pixY++) {
+            for(pixX = 0; pixX < 64; pixX = pixX + 4) {
+                int Pixel = pixY + pixX;
+                short VirPixelX = (RamBuf[Pixel * 2 + 1] << 8) + RamBuf[Pixel * 2];
+                xsprintf(buf, "info x:%d  y:%d  ea:%d  eb:%d  ed:%d  ra:%d\r\n", pixX, pixY, EEbuf[Pixel], EEbuf[Pixel + 0x40], EEbuf[Pixel + 0x80], VirPixelX);
+                pc.puts(buf);
+            }
+        }
+
+        ShowTempsVT100();
+        wait_ms(300);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 04 14:01:24 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7d30d6019079
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xprintf.c	Fri Apr 04 14:01:24 2014 +0000
@@ -0,0 +1,394 @@
+/*------------------------------------------------------------------------/
+/  Universal string handler for user console interface
+/-------------------------------------------------------------------------/
+/
+/  Copyright (C) 2011, ChaN, all right reserved.
+/
+/ * This software is a free software and there is NO WARRANTY.
+/ * No restriction on use. You can use, modify and redistribute it for
+/   personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
+/ * Redistributions of source code must retain the above copyright notice.
+/
+/-------------------------------------------------------------------------*/
+
+#include "xprintf.h"
+
+
+#if _USE_XFUNC_OUT
+#include <stdarg.h>
+void (*xfunc_out)(unsigned char);   /* Pointer to the output stream */
+static char *outptr;
+
+/*----------------------------------------------*/
+/* Put a character                              */
+/*----------------------------------------------*/
+
+void xputc (char c)
+{
+    if (_CR_CRLF && c == '\n') xputc('\r');     /* CR -> CRLF */
+
+    if (outptr) {
+        *outptr++ = (unsigned char)c;
+        return;
+    }
+
+    if (xfunc_out) xfunc_out((unsigned char)c);
+}
+
+
+
+/*----------------------------------------------*/
+/* Put a null-terminated string                 */
+/*----------------------------------------------*/
+
+void xputs (                    /* Put a string to the default device */
+    const char* str             /* Pointer to the string */
+)
+{
+    while (*str)
+        xputc(*str++);
+}
+
+
+void xfputs (                   /* Put a string to the specified device */
+    void(*func)(unsigned char), /* Pointer to the output function */
+    const char* str             /* Pointer to the string */
+)
+{
+    void (*pf)(unsigned char);
+
+
+    pf = xfunc_out;     /* Save current output device */
+    xfunc_out = func;   /* Switch output to specified device */
+    while (*str)        /* Put the string */
+        xputc(*str++);
+    xfunc_out = pf;     /* Restore output device */
+}
+
+
+
+/*----------------------------------------------*/
+/* Formatted string output                      */
+/*----------------------------------------------*/
+/*  xprintf("%d", 1234);            "1234"
+    xprintf("%6d,%3d%%", -200, 5);  "  -200,  5%"
+    xprintf("%-6u", 100);           "100   "
+    xprintf("%ld", 12345678L);      "12345678"
+    xprintf("%04x", 0xA3);          "00a3"
+    xprintf("%08LX", 0x123ABC);     "00123ABC"
+    xprintf("%016b", 0x550F);       "0101010100001111"
+    xprintf("%s", "String");        "String"
+    xprintf("%-4s", "abc");         "abc "
+    xprintf("%4s", "abc");          " abc"
+    xprintf("%c", 'a');             "a"
+    xprintf("%f", 10.0);            <xprintf lacks floating point support>
+*/
+
+static
+void xvprintf (
+    const char* fmt,    /* Pointer to the format string */
+    va_list arp         /* Pointer to arguments */
+)
+{
+    unsigned int r, i, j, w, f;
+    unsigned long v;
+    char s[16], c, d, *p;
+
+
+    for (;;) {
+        c = *fmt++;                 /* Get a char */
+        if (!c) break;              /* End of format? */
+        if (c != '%') {             /* Pass through it if not a % sequense */
+            xputc(c); continue;
+        }
+        f = 0;
+        c = *fmt++;                 /* Get first char of the sequense */
+        if (c == '0') {             /* Flag: '0' padded */
+            f = 1; c = *fmt++;
+        } else {
+            if (c == '-') {         /* Flag: left justified */
+                f = 2; c = *fmt++;
+            }
+        }
+        for (w = 0; c >= '0' && c <= '9'; c = *fmt++)   /* Minimum width */
+            w = w * 10 + c - '0';
+        if (c == 'l' || c == 'L') { /* Prefix: Size is long int */
+            f |= 4; c = *fmt++;
+        }
+        if (!c) break;              /* End of format? */
+        d = c;
+        if (d >= 'a') d -= 0x20;
+        switch (d) {                /* Type is... */
+        case 'S' :                  /* String */
+            p = va_arg(arp, char*);
+            for (j = 0; p[j]; j++) ;
+            while (!(f & 2) && j++ < w) xputc(' ');
+            xputs(p);
+            while (j++ < w) xputc(' ');
+            continue;
+        case 'C' :                  /* Character */
+            xputc((char)va_arg(arp, int)); continue;
+        case 'B' :                  /* Binary */
+            r = 2; break;
+        case 'O' :                  /* Octal */
+            r = 8; break;
+        case 'D' :                  /* Signed decimal */
+        case 'U' :                  /* Unsigned decimal */
+            r = 10; break;
+        case 'X' :                  /* Hexdecimal */
+            r = 16; break;
+        default:                    /* Unknown type (passthrough) */
+            xputc(c); continue;
+        }
+
+        /* Get an argument and put it in numeral */
+        v = (f & 4) ? va_arg(arp, long) : ((d == 'D') ? (long)va_arg(arp, int) : (long)va_arg(arp, unsigned int));
+        if (d == 'D' && (v & 0x80000000)) {
+            v = 0 - v;
+            f |= 8;
+        }
+        i = 0;
+        do {
+            d = (char)(v % r); v /= r;
+            if (d > 9) d += (c == 'x') ? 0x27 : 0x07;
+            s[i++] = d + '0';
+        } while (v && i < sizeof(s));
+        if (f & 8) s[i++] = '-';
+        j = i; d = (f & 1) ? '0' : ' ';
+        while (!(f & 2) && j++ < w) xputc(d);
+        do xputc(s[--i]); while(i);
+        while (j++ < w) xputc(' ');
+    }
+}
+
+
+void xprintf (          /* Put a formatted string to the default device */
+    const char* fmt,    /* Pointer to the format string */
+    ...                 /* Optional arguments */
+)
+{
+    va_list arp;
+
+
+    va_start(arp, fmt);
+    xvprintf(fmt, arp);
+    va_end(arp);
+}
+
+
+void xsprintf (         /* Put a formatted string to the memory */
+    char* buff,         /* Pointer to the output buffer */
+    const char* fmt,    /* Pointer to the format string */
+    ...                 /* Optional arguments */
+)
+{
+    va_list arp;
+
+
+    outptr = buff;      /* Switch destination for memory */
+
+    va_start(arp, fmt);
+    xvprintf(fmt, arp);
+    va_end(arp);
+
+    *outptr = 0;        /* Terminate output string with a \0 */
+    outptr = 0;         /* Switch destination for device */
+}
+
+
+void xfprintf (                 /* Put a formatted string to the specified device */
+    void(*func)(unsigned char), /* Pointer to the output function */
+    const char* fmt,            /* Pointer to the format string */
+    ...                         /* Optional arguments */
+)
+{
+    va_list arp;
+    void (*pf)(unsigned char);
+
+
+    pf = xfunc_out;     /* Save current output device */
+    xfunc_out = func;   /* Switch output to specified device */
+
+    va_start(arp, fmt);
+    xvprintf(fmt, arp);
+    va_end(arp);
+
+    xfunc_out = pf;     /* Restore output device */
+}
+
+
+
+/*----------------------------------------------*/
+/* Dump a line of binary dump                   */
+/*----------------------------------------------*/
+
+void put_dump (
+    const void* buff,       /* Pointer to the array to be dumped */
+    unsigned long addr,     /* Heading address value */
+    int len,                /* Number of items to be dumped */
+    int width               /* Size of the items (DF_CHAR, DF_SHORT, DF_LONG) */
+)
+{
+    int i;
+    const unsigned char *bp;
+    const unsigned short *sp;
+    const unsigned long *lp;
+
+
+    xprintf("%08lX ", addr);        /* address */
+
+    switch (width) {
+    case DW_CHAR:
+        bp = buff;
+        for (i = 0; i < len; i++)       /* Hexdecimal dump */
+            xprintf(" %02X", bp[i]);
+        xputc(' ');
+        for (i = 0; i < len; i++)       /* ASCII dump */
+            xputc((bp[i] >= ' ' && bp[i] <= '~') ? bp[i] : '.');
+        break;
+    case DW_SHORT:
+        sp = buff;
+        do                              /* Hexdecimal dump */
+            xprintf(" %04X", *sp++);
+        while (--len);
+        break;
+    case DW_LONG:
+        lp = buff;
+        do                              /* Hexdecimal dump */
+            xprintf(" %08LX", *lp++);
+        while (--len);
+        break;
+    }
+
+    xputc('\n');
+}
+
+#endif /* _USE_XFUNC_OUT */
+
+
+
+#if _USE_XFUNC_IN
+unsigned char (*xfunc_in)(void);    /* Pointer to the input stream */
+
+/*----------------------------------------------*/
+/* Get a line from the input                    */
+/*----------------------------------------------*/
+
+int xgets (     /* 0:End of stream, 1:A line arrived */
+    char* buff, /* Pointer to the buffer */
+    int len     /* Buffer length */
+)
+{
+    int c, i;
+
+
+    if (!xfunc_in) return 0;        /* No input function specified */
+
+    i = 0;
+    for (;;) {
+        c = xfunc_in();             /* Get a char from the incoming stream */
+        if (!c) return 0;           /* End of stream? */
+        if (c == '\r') break;       /* End of line? */
+        if (c == '\b' && i) {       /* Back space? */
+            i--;
+            if (_LINE_ECHO) xputc(c);
+            continue;
+        }
+        if (c >= ' ' && i < len - 1) {  /* Visible chars */
+            buff[i++] = c;
+            if (_LINE_ECHO) xputc(c);
+        }
+    }
+    buff[i] = 0;    /* Terminate with a \0 */
+    if (_LINE_ECHO) xputc('\n');
+    return 1;
+}
+
+
+int xfgets (    /* 0:End of stream, 1:A line arrived */
+    unsigned char (*func)(void),    /* Pointer to the input stream function */
+    char* buff, /* Pointer to the buffer */
+    int len     /* Buffer length */
+)
+{
+    unsigned char (*pf)(void);
+    int n;
+
+
+    pf = xfunc_in;          /* Save current input device */
+    xfunc_in = func;        /* Switch input to specified device */
+    n = xgets(buff, len);   /* Get a line */
+    xfunc_in = pf;          /* Restore input device */
+
+    return n;
+}
+
+
+/*----------------------------------------------*/
+/* Get a value of the string                    */
+/*----------------------------------------------*/
+/*  "123 -5   0x3ff 0b1111 0377  w "
+        ^                           1st call returns 123 and next ptr
+           ^                        2nd call returns -5 and next ptr
+                   ^                3rd call returns 1023 and next ptr
+                          ^         4th call returns 15 and next ptr
+                               ^    5th call returns 255 and next ptr
+                                  ^ 6th call fails and returns 0
+*/
+
+int xatoi (         /* 0:Failed, 1:Successful */
+    char **str,     /* Pointer to pointer to the string */
+    long *res       /* Pointer to the valiable to store the value */
+)
+{
+    unsigned long val;
+    unsigned char c, r, s = 0;
+
+
+    *res = 0;
+
+    while ((c = **str) == ' ') (*str)++;    /* Skip leading spaces */
+
+    if (c == '-') {     /* negative? */
+        s = 1;
+        c = *(++(*str));
+    }
+
+    if (c == '0') {
+        c = *(++(*str));
+        switch (c) {
+        case 'x':       /* hexdecimal */
+            r = 16; c = *(++(*str));
+            break;
+        case 'b':       /* binary */
+            r = 2; c = *(++(*str));
+            break;
+        default:
+            if (c <= ' ') return 1; /* single zero */
+            if (c < '0' || c > '9') return 0;   /* invalid char */
+            r = 8;      /* octal */
+        }
+    } else {
+        if (c < '0' || c > '9') return 0;   /* EOL or invalid char */
+        r = 10;         /* decimal */
+    }
+
+    val = 0;
+    while (c > ' ') {
+        if (c >= 'a') c -= 0x20;
+        c -= '0';
+        if (c >= 17) {
+            c -= 7;
+            if (c <= 9) return 0;   /* invalid char */
+        }
+        if (c >= r) return 0;       /* invalid char for current radix */
+        val = val * r + c;
+        c = *(++(*str));
+    }
+    if (s) val = 0 - val;           /* apply sign if needed */
+
+    *res = val;
+    return 1;
+}
+
+#endif /* _USE_XFUNC_IN */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xprintf.h	Fri Apr 04 14:01:24 2014 +0000
@@ -0,0 +1,38 @@
+/*------------------------------------------------------------------------*/
+/* Universal string handler for user console interface  (C)ChaN, 2011     */
+/*------------------------------------------------------------------------*/
+
+#ifndef _STRFUNC
+#define _STRFUNC
+
+#define _USE_XFUNC_OUT  1   /* 1: Use output functions */
+#define _CR_CRLF        1   /* 1: Convert \n ==> \r\n in the output char */
+
+#define _USE_XFUNC_IN   0   /* 1: Use input function */
+#define _LINE_ECHO      0   /* 1: Echo back input chars in xgets function */
+
+
+#if _USE_XFUNC_OUT
+#define xdev_out(func) xfunc_out = (void(*)(unsigned char))(func)
+extern void (*xfunc_out)(unsigned char);
+void xputc (char c);
+void xputs (const char* str);
+void xfputs (void (*func)(unsigned char), const char* str);
+void xprintf (const char* fmt, ...);
+void xsprintf (char* buff, const char* fmt, ...);
+void xfprintf (void (*func)(unsigned char), const char* fmt, ...);
+void put_dump (const void* buff, unsigned long addr, int len, int width);
+#define DW_CHAR     sizeof(char)
+#define DW_SHORT    sizeof(short)
+#define DW_LONG     sizeof(long)
+#endif
+
+#if _USE_XFUNC_IN
+#define xdev_in(func) xfunc_in = (unsigned char(*)(void))(func)
+extern unsigned char (*xfunc_in)(void);
+int xgets (char* buff, int len);
+int xfgets (unsigned char (*func)(void), char* buff, int len);
+int xatoi (char** str, long* res);
+#endif
+
+#endif