demo sample to drive PCU9955 and PCA9629

Dependencies:   mbed I2C_slaves PCU9669 parallel_bus

Fork of mini_board_PCU9669 by InetrfaceProducts NXP

What is this?

This is a sample code to operate PCU9955 (16ch constant-current LED controller) and PCA9629 (intelligent stepper motor controller) through PCU9669 (3 channels (UltraFast mode * 2ch, FastModePlus *1ch) I2C bus controller).

This demo is written based on mini_board_PCU9669 sample code library and its API.
http://mbed.org/users/nxp_ip/code/mini_board_PCU9669/

Demo will shows how the LED controllers and stepper motor controllers works.
It uses a mini_board_PCU9669 board with mbed, 8 of PCU9955s and 5 PCA9629s.

/media/uploads/nxp_ip/dsc_0414ss.png
Demo setup
(left-top: PCU9955 boards, left-bottom: mini-board PCU9669 with mbed, right: PCA9629 x5 board)

/media/uploads/nxp_ip/demo-config-ss.png
Board connections and device addresses

Reference:

User manual of PCU9669 demo board: Mini board PCU9669

http://www.nxp.com/documents/user_manual/UM10580.pdf

sample code : mbed programs

Import programmini_board_PCU9669

mini board PCU9669 (and PCA9665) sample code

Import programPCA9955_Hello

PCA9955 16 channel current drive(sink) LED driver sample code

Import programPCA9955_simple

very simple sample code for PCA9955 (16 channel current control LED driver)

Import programPCA9629_Hello

Sample code for PCA9629 operation

device infomation

PCU9669 (Parallel bus to 1 channel Fm+ and 2 channel UFm I2C-bus controller)
PCU9955 (16-channel UFm I²C-bus 57 mA constant current LED driver)
PCA9955 (16-channel Fm+ I²C-bus 57 mA constant current LED driver)
PCU9629 (Fm+ I2C-bus stepper motor controller)

Committer:
nxp_ip
Date:
Fri Oct 26 07:03:47 2012 +0000
Revision:
21:3b75b545ecfb
Parent:
20:a266fa588bd8
PCU9669, PCU9955 and PCA9629 demo code version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 21:3b75b545ecfb 1 #include "demo_patterns.h"
nxp_ip 21:3b75b545ecfb 2 #include "transfer_manager.h"
nxp_ip 21:3b75b545ecfb 3 #include "PCx9955_reg.h"
nxp_ip 21:3b75b545ecfb 4 #include "PCA9629_reg.h"
nxp_ip 21:3b75b545ecfb 5 #include "PCU9669_access.h" // PCU9669 chip access interface
nxp_ip 21:3b75b545ecfb 6
nxp_ip 21:3b75b545ecfb 7 #include "mbed.h"
nxp_ip 21:3b75b545ecfb 8
nxp_ip 21:3b75b545ecfb 9 typedef struct pattern_st {
nxp_ip 21:3b75b545ecfb 10 int duration;
nxp_ip 21:3b75b545ecfb 11 void (*pattern_func)( int count );
nxp_ip 21:3b75b545ecfb 12 }
nxp_ip 21:3b75b545ecfb 13 pattern;
nxp_ip 21:3b75b545ecfb 14
nxp_ip 21:3b75b545ecfb 15 char gLEDs[ N_OF_LEDS ] = { 0 };
nxp_ip 21:3b75b545ecfb 16 int gCount = 0;
nxp_ip 21:3b75b545ecfb 17
nxp_ip 21:3b75b545ecfb 18 char nine_step_intensity[] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF };
nxp_ip 21:3b75b545ecfb 19 char sixteen_step_intensity[] = { 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 };
nxp_ip 21:3b75b545ecfb 20
nxp_ip 21:3b75b545ecfb 21 char gMot_cntl_order[ 5 ] = { MOT_ADDR5, MOT_ADDR6, MOT_ADDR7, MOT_ADDR8, MOT_ADDR9 };
nxp_ip 21:3b75b545ecfb 22 char gMot_cntl_order_halfturn[ 10 ] = { MOT_ADDR5, 0, MOT_ADDR6, MOT_ADDR7, MOT_ADDR8, MOT_ADDR9, 0, MOT_ADDR8, MOT_ADDR7, MOT_ADDR6 };
nxp_ip 21:3b75b545ecfb 23 char gMotor_count;
nxp_ip 21:3b75b545ecfb 24
nxp_ip 21:3b75b545ecfb 25 typedef enum {
nxp_ip 21:3b75b545ecfb 26 RED,
nxp_ip 21:3b75b545ecfb 27 GREEN,
nxp_ip 21:3b75b545ecfb 28 BLUE,
nxp_ip 21:3b75b545ecfb 29 }
nxp_ip 21:3b75b545ecfb 30 color;
nxp_ip 21:3b75b545ecfb 31
nxp_ip 21:3b75b545ecfb 32 char rgb_mask[ 3 ][ 15 ] = {
nxp_ip 21:3b75b545ecfb 33 { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
nxp_ip 21:3b75b545ecfb 34 { 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0 },
nxp_ip 21:3b75b545ecfb 35 { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0 }
nxp_ip 21:3b75b545ecfb 36 };
nxp_ip 21:3b75b545ecfb 37
nxp_ip 21:3b75b545ecfb 38 char led_init_array[] = {
nxp_ip 21:3b75b545ecfb 39 0x80, // Command
nxp_ip 21:3b75b545ecfb 40 0x00, 0x05, // MODE1, MODE2
nxp_ip 21:3b75b545ecfb 41 0xAA, 0xAA, 0xAA, 0xAA, // LEDOUT[3:0]
nxp_ip 21:3b75b545ecfb 42 0x80, 0x00, // GRPPWM, GRPFREQ
nxp_ip 21:3b75b545ecfb 43 PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, // PWM[7:0]
nxp_ip 21:3b75b545ecfb 44 PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, PWM_INIT, // PWM[15:8]
nxp_ip 21:3b75b545ecfb 45 IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[7:0]
nxp_ip 21:3b75b545ecfb 46 IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, IREF_INIT, // IREF[15:8]
nxp_ip 21:3b75b545ecfb 47 0x08 // OFFSET: 1uS offsets
nxp_ip 21:3b75b545ecfb 48 };
nxp_ip 21:3b75b545ecfb 49
nxp_ip 21:3b75b545ecfb 50 char led_norm_op_array[] = {
nxp_ip 21:3b75b545ecfb 51 0x80 | PWM0, // Command
nxp_ip 21:3b75b545ecfb 52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[7:0]
nxp_ip 21:3b75b545ecfb 53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // PWM[14:8]
nxp_ip 21:3b75b545ecfb 54 };
nxp_ip 21:3b75b545ecfb 55
nxp_ip 21:3b75b545ecfb 56 char mot_init_array[] = {
nxp_ip 21:3b75b545ecfb 57 0x80,
nxp_ip 21:3b75b545ecfb 58 0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0x02, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06
nxp_ip 21:3b75b545ecfb 59 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08)
nxp_ip 21:3b75b545ecfb 60 0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x01, 0x01, 0x00, 0x01, // for registers OP - INT_AUTO_CLR (0x09 - 0x11)
nxp_ip 21:3b75b545ecfb 61 0x00, 0x00, 0x30, 0x00, 0x82, 0x06, 0x82, 0x06, // for registers SETMODE - CCWPWH (0x12 - 0x19)
nxp_ip 21:3b75b545ecfb 62 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
nxp_ip 21:3b75b545ecfb 63 0x00, 0x00, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
nxp_ip 21:3b75b545ecfb 64 0x00, 0x00, 0x84 // for registers RMPCNTL - MCNTL (0x24 - 0x26)
nxp_ip 21:3b75b545ecfb 65 };
nxp_ip 21:3b75b545ecfb 66
nxp_ip 21:3b75b545ecfb 67 char mot_all_stop[] = {
nxp_ip 21:3b75b545ecfb 68 0x26, 0x00
nxp_ip 21:3b75b545ecfb 69 };
nxp_ip 21:3b75b545ecfb 70
nxp_ip 21:3b75b545ecfb 71 char mot_all_start[] = {
nxp_ip 21:3b75b545ecfb 72 0x26, 0xBA
nxp_ip 21:3b75b545ecfb 73 };
nxp_ip 21:3b75b545ecfb 74
nxp_ip 21:3b75b545ecfb 75 char mot_ramp_array[] = {
nxp_ip 21:3b75b545ecfb 76 0x80,
nxp_ip 21:3b75b545ecfb 77 0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0xFF, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06
nxp_ip 21:3b75b545ecfb 78 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08)
nxp_ip 21:3b75b545ecfb 79 0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x00, 0x03, 0x03, 0x01, // for registers OP - INT_AUTO_CLR (0x09 - 0x11)
nxp_ip 21:3b75b545ecfb 80 0x00, 0x00, 0x30, 0x00, 0x97, 0x04, 0x97, 0x04, // for registers SETMODE - CCWPWH (0x12 - 0x19)
nxp_ip 21:3b75b545ecfb 81 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
nxp_ip 21:3b75b545ecfb 82 0x0C, 0x0C, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
nxp_ip 21:3b75b545ecfb 83 0x37, 0x00, 0x88 // for registers RMPCNTL - MCNTL (0x24 - 0x26)
nxp_ip 21:3b75b545ecfb 84 };
nxp_ip 21:3b75b545ecfb 85
nxp_ip 21:3b75b545ecfb 86 char mot_vib_array[] = {
nxp_ip 21:3b75b545ecfb 87 0x80,
nxp_ip 21:3b75b545ecfb 88 0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0xFF, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06
nxp_ip 21:3b75b545ecfb 89 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08)
nxp_ip 21:3b75b545ecfb 90 0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x00, 0x03, 0x03, 0x01, // for registers OP - INT_AUTO_CLR (0x09 - 0x11)
nxp_ip 21:3b75b545ecfb 91 0x00, 0x00, 0x30, 0x00, 0x82, 0x06, 0x82, 0x06, // for registers SETMODE - CCWPWH (0x12 - 0x19)
nxp_ip 21:3b75b545ecfb 92 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
nxp_ip 21:3b75b545ecfb 93 0x0C, 0x0C, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
nxp_ip 21:3b75b545ecfb 94 0x00, 0x00, 0xBA // for registers RMPCNTL - MCNTL (0x24 - 0x26)
nxp_ip 21:3b75b545ecfb 95 };
nxp_ip 21:3b75b545ecfb 96
nxp_ip 21:3b75b545ecfb 97 //#define INTERVAL128MS
nxp_ip 21:3b75b545ecfb 98 #ifdef INTERVAL128MS
nxp_ip 21:3b75b545ecfb 99 char mot_norm_op_array[] = {
nxp_ip 21:3b75b545ecfb 100 0x80,
nxp_ip 21:3b75b545ecfb 101 0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0x02, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06
nxp_ip 21:3b75b545ecfb 102 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08)
nxp_ip 21:3b75b545ecfb 103 0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x00, 0x01, 0x00, 0x01, // for registers OP - INT_AUTO_CLR (0x09 - 0x11)
nxp_ip 21:3b75b545ecfb 104 0x00, 0x00, 0x30, 0x00, 0xF2, 0x06, 0xF2, 0x06, // for registers SETMODE - CCWPWH (0x12 - 0x19)
nxp_ip 21:3b75b545ecfb 105 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
nxp_ip 21:3b75b545ecfb 106 0x00, 0x00, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
nxp_ip 21:3b75b545ecfb 107 0x00, 0x00, 0x00 // for registers RMPCNTL - MCNTL (0x24 - 0x26)
nxp_ip 21:3b75b545ecfb 108 };
nxp_ip 21:3b75b545ecfb 109
nxp_ip 21:3b75b545ecfb 110 char mot_half_array[] = {
nxp_ip 21:3b75b545ecfb 111 0x80,
nxp_ip 21:3b75b545ecfb 112 0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0x02, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06
nxp_ip 21:3b75b545ecfb 113 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08)
nxp_ip 21:3b75b545ecfb 114 0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x00, 0x01, 0x00, 0x01, // for registers OP - INT_AUTO_CLR (0x09 - 0x11)
nxp_ip 21:3b75b545ecfb 115 0x00, 0x00, 0x30, 0x00, 0xF2, 0x06, 0xF2, 0x06, // for registers SETMODE - CCWPWH (0x12 - 0x19)
nxp_ip 21:3b75b545ecfb 116 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
nxp_ip 21:3b75b545ecfb 117 0x00, 0x00, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
nxp_ip 21:3b75b545ecfb 118 0x00, 0x00, 0x00 // for registers RMPCNTL - MCNTL (0x24 - 0x26)
nxp_ip 21:3b75b545ecfb 119 };
nxp_ip 21:3b75b545ecfb 120 #else
nxp_ip 21:3b75b545ecfb 121 char mot_norm_op_array[] = {
nxp_ip 21:3b75b545ecfb 122 0x80,
nxp_ip 21:3b75b545ecfb 123 0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0x02, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06
nxp_ip 21:3b75b545ecfb 124 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08)
nxp_ip 21:3b75b545ecfb 125 0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x00, 0x01, 0x00, 0x01, // for registers OP - INT_AUTO_CLR (0x09 - 0x11)
nxp_ip 21:3b75b545ecfb 126 0x00, 0x00, 0x30, 0x00, 0xE4, 0x0D, 0xE4, 0x0D, // for registers SETMODE - CCWPWH (0x12 - 0x19)
nxp_ip 21:3b75b545ecfb 127 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
nxp_ip 21:3b75b545ecfb 128 0x00, 0x00, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
nxp_ip 21:3b75b545ecfb 129 0x00, 0x00, 0x00 // for registers RMPCNTL - MCNTL (0x24 - 0x26)
nxp_ip 21:3b75b545ecfb 130 };
nxp_ip 21:3b75b545ecfb 131
nxp_ip 21:3b75b545ecfb 132 char mot_half_array[] = {
nxp_ip 21:3b75b545ecfb 133 0x80,
nxp_ip 21:3b75b545ecfb 134 0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0x02, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06
nxp_ip 21:3b75b545ecfb 135 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08)
nxp_ip 21:3b75b545ecfb 136 0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x00, 0x01, 0x00, 0x01, // for registers OP - INT_AUTO_CLR (0x09 - 0x11)
nxp_ip 21:3b75b545ecfb 137 0x00, 0x00, 0x30, 0x00, 0xE4, 0x0D, 0xE4, 0x0D, // for registers SETMODE - CCWPWH (0x12 - 0x19)
nxp_ip 21:3b75b545ecfb 138 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
nxp_ip 21:3b75b545ecfb 139 0x00, 0x00, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
nxp_ip 21:3b75b545ecfb 140 0x00, 0x00, 0x00 // for registers RMPCNTL - MCNTL (0x24 - 0x26)
nxp_ip 21:3b75b545ecfb 141 };
nxp_ip 21:3b75b545ecfb 142 #endif
nxp_ip 21:3b75b545ecfb 143
nxp_ip 21:3b75b545ecfb 144
nxp_ip 21:3b75b545ecfb 145 transaction led_init_transfer[] = {
nxp_ip 21:3b75b545ecfb 146 { PCx9955_ADDR0, led_init_array, sizeof( led_init_array ) },
nxp_ip 21:3b75b545ecfb 147 { PCx9955_ADDR1, led_init_array, sizeof( led_init_array ) },
nxp_ip 21:3b75b545ecfb 148 { PCx9955_ADDR2, led_init_array, sizeof( led_init_array ) },
nxp_ip 21:3b75b545ecfb 149 { PCx9955_ADDR3, led_init_array, sizeof( led_init_array ) },
nxp_ip 21:3b75b545ecfb 150 };
nxp_ip 21:3b75b545ecfb 151
nxp_ip 21:3b75b545ecfb 152 transaction led_norm_op_transfer[] = {
nxp_ip 21:3b75b545ecfb 153 { PCx9955_ADDR0, led_norm_op_array, sizeof( led_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 154 { PCx9955_ADDR1, led_norm_op_array, sizeof( led_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 155 { PCx9955_ADDR2, led_norm_op_array, sizeof( led_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 156 { PCx9955_ADDR3, led_norm_op_array, sizeof( led_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 157 };
nxp_ip 21:3b75b545ecfb 158
nxp_ip 21:3b75b545ecfb 159 transaction mot_init_transfer[] = {
nxp_ip 21:3b75b545ecfb 160 { MOT_ADDR5, mot_init_array, sizeof( mot_init_array ) },
nxp_ip 21:3b75b545ecfb 161 { MOT_ADDR6, mot_init_array, sizeof( mot_init_array ) },
nxp_ip 21:3b75b545ecfb 162 { MOT_ADDR7, mot_init_array, sizeof( mot_init_array ) },
nxp_ip 21:3b75b545ecfb 163 { MOT_ADDR8, mot_init_array, sizeof( mot_init_array ) },
nxp_ip 21:3b75b545ecfb 164 { MOT_ADDR9, mot_init_array, sizeof( mot_init_array ) },
nxp_ip 21:3b75b545ecfb 165 };
nxp_ip 21:3b75b545ecfb 166
nxp_ip 21:3b75b545ecfb 167 transaction mot_norm_op_transfer[] = {
nxp_ip 21:3b75b545ecfb 168 { MOT_ADDR5, mot_norm_op_array, sizeof( mot_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 169 { MOT_ADDR6, mot_norm_op_array, sizeof( mot_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 170 { MOT_ADDR7, mot_norm_op_array, sizeof( mot_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 171 { MOT_ADDR8, mot_norm_op_array, sizeof( mot_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 172 { MOT_ADDR9, mot_norm_op_array, sizeof( mot_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 173 };
nxp_ip 21:3b75b545ecfb 174
nxp_ip 21:3b75b545ecfb 175 transaction mot_half_transfer[] = {
nxp_ip 21:3b75b545ecfb 176 { MOT_ADDR5, mot_norm_op_array, sizeof( mot_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 177 { MOT_ADDR6, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 178 { MOT_ADDR7, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 179 { MOT_ADDR8, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 180 { MOT_ADDR9, mot_norm_op_array, sizeof( mot_norm_op_array ) },
nxp_ip 21:3b75b545ecfb 181 };
nxp_ip 21:3b75b545ecfb 182
nxp_ip 21:3b75b545ecfb 183 transaction mot_half_setup_transfer[] = {
nxp_ip 21:3b75b545ecfb 184 { MOT_ADDR5, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 185 { MOT_ADDR6, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 186 { MOT_ADDR7, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 187 { MOT_ADDR8, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 188 { MOT_ADDR9, mot_half_array, sizeof( mot_half_array ) },
nxp_ip 21:3b75b545ecfb 189 };
nxp_ip 21:3b75b545ecfb 190
nxp_ip 21:3b75b545ecfb 191 transaction mot_all_stop_transfer[] = {
nxp_ip 21:3b75b545ecfb 192 { MOT_ADDR5, mot_all_stop, sizeof( mot_all_stop ) },
nxp_ip 21:3b75b545ecfb 193 { MOT_ADDR6, mot_all_stop, sizeof( mot_all_stop ) },
nxp_ip 21:3b75b545ecfb 194 { MOT_ADDR7, mot_all_stop, sizeof( mot_all_stop ) },
nxp_ip 21:3b75b545ecfb 195 { MOT_ADDR8, mot_all_stop, sizeof( mot_all_stop ) },
nxp_ip 21:3b75b545ecfb 196 { MOT_ADDR9, mot_all_stop, sizeof( mot_all_stop ) },
nxp_ip 21:3b75b545ecfb 197 };
nxp_ip 21:3b75b545ecfb 198
nxp_ip 21:3b75b545ecfb 199 transaction mot_all_start_transfer[] = {
nxp_ip 21:3b75b545ecfb 200 { MOT_ADDR5, mot_all_start, sizeof( mot_all_start ) },
nxp_ip 21:3b75b545ecfb 201 { MOT_ADDR6, mot_all_start, sizeof( mot_all_start ) },
nxp_ip 21:3b75b545ecfb 202 { MOT_ADDR7, mot_all_start, sizeof( mot_all_start ) },
nxp_ip 21:3b75b545ecfb 203 { MOT_ADDR8, mot_all_start, sizeof( mot_all_start ) },
nxp_ip 21:3b75b545ecfb 204 { MOT_ADDR9, mot_all_start, sizeof( mot_all_start ) },
nxp_ip 21:3b75b545ecfb 205 };
nxp_ip 21:3b75b545ecfb 206
nxp_ip 21:3b75b545ecfb 207 transaction mot_all_vib_transfer[] = {
nxp_ip 21:3b75b545ecfb 208 { MOT_ADDR5, mot_vib_array, sizeof( mot_vib_array ) },
nxp_ip 21:3b75b545ecfb 209 { MOT_ADDR6, mot_vib_array, sizeof( mot_vib_array ) },
nxp_ip 21:3b75b545ecfb 210 { MOT_ADDR7, mot_vib_array, sizeof( mot_vib_array ) },
nxp_ip 21:3b75b545ecfb 211 { MOT_ADDR8, mot_vib_array, sizeof( mot_vib_array ) },
nxp_ip 21:3b75b545ecfb 212 { MOT_ADDR9, mot_vib_array, sizeof( mot_vib_array ) },
nxp_ip 21:3b75b545ecfb 213 };
nxp_ip 21:3b75b545ecfb 214
nxp_ip 21:3b75b545ecfb 215 transaction mot_all_ramp_transfer[] = {
nxp_ip 21:3b75b545ecfb 216 { MOT_ADDR5, mot_ramp_array, sizeof( mot_ramp_array ) },
nxp_ip 21:3b75b545ecfb 217 { MOT_ADDR6, mot_ramp_array, sizeof( mot_ramp_array ) },
nxp_ip 21:3b75b545ecfb 218 { MOT_ADDR7, mot_ramp_array, sizeof( mot_ramp_array ) },
nxp_ip 21:3b75b545ecfb 219 { MOT_ADDR8, mot_ramp_array, sizeof( mot_ramp_array ) },
nxp_ip 21:3b75b545ecfb 220 { MOT_ADDR9, mot_ramp_array, sizeof( mot_ramp_array ) },
nxp_ip 21:3b75b545ecfb 221 };
nxp_ip 21:3b75b545ecfb 222
nxp_ip 21:3b75b545ecfb 223 void init_slave_devices( void )
nxp_ip 21:3b75b545ecfb 224 {
nxp_ip 21:3b75b545ecfb 225 // init all slave's registers
nxp_ip 21:3b75b545ecfb 226 setup_transfer( CH_FM_PLUS, mot_init_transfer, sizeof( mot_init_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 227 setup_transfer( CH_UFM1, led_init_transfer, sizeof( led_init_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 228 setup_transfer( CH_UFM2, led_init_transfer, sizeof( led_init_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 229 start( CH_FM_PLUS ); // motors are aligned using interrupt input of PCA9629
nxp_ip 21:3b75b545ecfb 230 start( CH_UFM1 );
nxp_ip 21:3b75b545ecfb 231 start( CH_UFM2 );
nxp_ip 21:3b75b545ecfb 232
nxp_ip 21:3b75b545ecfb 233 wait_sec( 0.5 );
nxp_ip 21:3b75b545ecfb 234
nxp_ip 21:3b75b545ecfb 235 // update motor control buffer configuration
nxp_ip 21:3b75b545ecfb 236
nxp_ip 21:3b75b545ecfb 237 setup_transfer( CH_FM_PLUS, mot_norm_op_transfer, sizeof( mot_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 238 setup_transfer( CH_UFM1, led_norm_op_transfer, sizeof( led_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 239 setup_transfer( CH_UFM2, led_norm_op_transfer, sizeof( led_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 240 start( CH_FM_PLUS ); // just update PCA9629 registers. no motor action
nxp_ip 21:3b75b545ecfb 241 start( CH_UFM1 );
nxp_ip 21:3b75b545ecfb 242 start( CH_UFM2 );
nxp_ip 21:3b75b545ecfb 243 }
nxp_ip 21:3b75b545ecfb 244
nxp_ip 21:3b75b545ecfb 245 void single_byte_write_into_a_PCA9629( char ch, char i2c_addr, char reg_addr, char val )
nxp_ip 21:3b75b545ecfb 246 {
nxp_ip 21:3b75b545ecfb 247 transaction t;
nxp_ip 21:3b75b545ecfb 248 char data[ 2 ];
nxp_ip 21:3b75b545ecfb 249
nxp_ip 21:3b75b545ecfb 250 data[ 0 ] = reg_addr;
nxp_ip 21:3b75b545ecfb 251 data[ 1 ] = val;
nxp_ip 21:3b75b545ecfb 252
nxp_ip 21:3b75b545ecfb 253 t.i2c_address = i2c_addr;
nxp_ip 21:3b75b545ecfb 254 t.data = data;
nxp_ip 21:3b75b545ecfb 255 t.length = 2;
nxp_ip 21:3b75b545ecfb 256
nxp_ip 21:3b75b545ecfb 257 setup_transfer( ch, &t, 1 );
nxp_ip 21:3b75b545ecfb 258 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 259 }
nxp_ip 21:3b75b545ecfb 260
nxp_ip 21:3b75b545ecfb 261 void ramp_all_PCA9629( void )
nxp_ip 21:3b75b545ecfb 262 {
nxp_ip 21:3b75b545ecfb 263 setup_transfer( CH_FM_PLUS, mot_all_ramp_transfer, sizeof( mot_all_ramp_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 264 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 265 }
nxp_ip 21:3b75b545ecfb 266 void vib_all_PCA9629( void )
nxp_ip 21:3b75b545ecfb 267 {
nxp_ip 21:3b75b545ecfb 268 setup_transfer( CH_FM_PLUS, mot_all_vib_transfer, sizeof( mot_all_vib_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 269 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 270 }
nxp_ip 21:3b75b545ecfb 271 void start_all_PCA9629( void )
nxp_ip 21:3b75b545ecfb 272 {
nxp_ip 21:3b75b545ecfb 273 setup_transfer( CH_FM_PLUS, mot_all_start_transfer, sizeof( mot_all_start_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 274 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 275 }
nxp_ip 21:3b75b545ecfb 276 void stop_all_PCA9629( void )
nxp_ip 21:3b75b545ecfb 277 {
nxp_ip 21:3b75b545ecfb 278 setup_transfer( CH_FM_PLUS, mot_all_stop_transfer, sizeof( mot_all_stop_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 279 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 280 }
nxp_ip 21:3b75b545ecfb 281 void align_all_PCA9629( void )
nxp_ip 21:3b75b545ecfb 282 {
nxp_ip 21:3b75b545ecfb 283 setup_transfer( CH_FM_PLUS, mot_init_transfer, sizeof( mot_init_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 284 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 285 }
nxp_ip 21:3b75b545ecfb 286
nxp_ip 21:3b75b545ecfb 287 void all_LEDs_value( char v )
nxp_ip 21:3b75b545ecfb 288 {
nxp_ip 21:3b75b545ecfb 289 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 290 gLEDs[ i ] = v;
nxp_ip 21:3b75b545ecfb 291 }
nxp_ip 21:3b75b545ecfb 292
nxp_ip 21:3b75b545ecfb 293 void all_LEDs_turn_off()
nxp_ip 21:3b75b545ecfb 294 {
nxp_ip 21:3b75b545ecfb 295 all_LEDs_value( 0x00 );
nxp_ip 21:3b75b545ecfb 296 }
nxp_ip 21:3b75b545ecfb 297
nxp_ip 21:3b75b545ecfb 298 void all_LEDs_turn_on()
nxp_ip 21:3b75b545ecfb 299 {
nxp_ip 21:3b75b545ecfb 300 all_LEDs_value( 0xFF );
nxp_ip 21:3b75b545ecfb 301 }
nxp_ip 21:3b75b545ecfb 302
nxp_ip 21:3b75b545ecfb 303 void pattern_rampup( int count )
nxp_ip 21:3b75b545ecfb 304 {
nxp_ip 21:3b75b545ecfb 305 if ( count == 0 ) {
nxp_ip 21:3b75b545ecfb 306 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 307 return;
nxp_ip 21:3b75b545ecfb 308 }
nxp_ip 21:3b75b545ecfb 309
nxp_ip 21:3b75b545ecfb 310 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 311 gLEDs[ i ] = count & 0xFF;
nxp_ip 21:3b75b545ecfb 312 }
nxp_ip 21:3b75b545ecfb 313
nxp_ip 21:3b75b545ecfb 314 void pattern_rampup_and_down( int count )
nxp_ip 21:3b75b545ecfb 315 {
nxp_ip 21:3b75b545ecfb 316 if ( !(count & 0xFF) ) {
nxp_ip 21:3b75b545ecfb 317 ramp_all_PCA9629();
nxp_ip 21:3b75b545ecfb 318 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 319 return;
nxp_ip 21:3b75b545ecfb 320 }
nxp_ip 21:3b75b545ecfb 321
nxp_ip 21:3b75b545ecfb 322 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 323 gLEDs[ i ] = (((count & 0x80) ? ~count : count) << 1) & 0xFF;
nxp_ip 21:3b75b545ecfb 324 }
nxp_ip 21:3b75b545ecfb 325
nxp_ip 21:3b75b545ecfb 326 void pattern_rampup_and_down_w_color( int count )
nxp_ip 21:3b75b545ecfb 327 {
nxp_ip 21:3b75b545ecfb 328 static int color;
nxp_ip 21:3b75b545ecfb 329
nxp_ip 21:3b75b545ecfb 330 color = (!count || (3 <= color)) ? 0 : color;
nxp_ip 21:3b75b545ecfb 331
nxp_ip 21:3b75b545ecfb 332 if ( !(count & 0xFF) ) {
nxp_ip 21:3b75b545ecfb 333 ramp_all_PCA9629();
nxp_ip 21:3b75b545ecfb 334 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 335 color++;
nxp_ip 21:3b75b545ecfb 336 return;
nxp_ip 21:3b75b545ecfb 337 }
nxp_ip 21:3b75b545ecfb 338
nxp_ip 21:3b75b545ecfb 339 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 340 gLEDs[ i ] = (rgb_mask[ color ][ i % N_LED_PER_BOARD ]) ? (((count & 0x80) ? ~count : count) << 1) & 0xFF : 0x00;
nxp_ip 21:3b75b545ecfb 341 }
nxp_ip 21:3b75b545ecfb 342
nxp_ip 21:3b75b545ecfb 343
nxp_ip 21:3b75b545ecfb 344 void pattern_colors2( int count )
nxp_ip 21:3b75b545ecfb 345 {
nxp_ip 21:3b75b545ecfb 346
nxp_ip 21:3b75b545ecfb 347 if ( !count ) {
nxp_ip 21:3b75b545ecfb 348 gMotor_count = 0;
nxp_ip 21:3b75b545ecfb 349 setup_transfer( CH_FM_PLUS, mot_norm_op_transfer, sizeof( mot_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 350 start( CH_FM_PLUS ); // just update PCA9629 registers. no motor action
nxp_ip 21:3b75b545ecfb 351 }
nxp_ip 21:3b75b545ecfb 352
nxp_ip 21:3b75b545ecfb 353 if ( !((count + 20) & 0x3F) ) {
nxp_ip 21:3b75b545ecfb 354 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order[ gMotor_count % 5 ], 0x26, 0x80 | ((gMotor_count / 5) & 0x1) );
nxp_ip 21:3b75b545ecfb 355 gMotor_count++;
nxp_ip 21:3b75b545ecfb 356 }
nxp_ip 21:3b75b545ecfb 357
nxp_ip 21:3b75b545ecfb 358 #define PI 3.14159265358979323846
nxp_ip 21:3b75b545ecfb 359
nxp_ip 21:3b75b545ecfb 360 float r;
nxp_ip 21:3b75b545ecfb 361 float g;
nxp_ip 21:3b75b545ecfb 362 float b;
nxp_ip 21:3b75b545ecfb 363 float k;
nxp_ip 21:3b75b545ecfb 364 float c;
nxp_ip 21:3b75b545ecfb 365 float f;
nxp_ip 21:3b75b545ecfb 366
nxp_ip 21:3b75b545ecfb 367 k = (2 * PI) / 300.0;
nxp_ip 21:3b75b545ecfb 368 c = count;
nxp_ip 21:3b75b545ecfb 369 f = 127.5 * ((count < 500) ? (float)count / 500.0 : 1.0);
nxp_ip 21:3b75b545ecfb 370
nxp_ip 21:3b75b545ecfb 371 #if 0
nxp_ip 21:3b75b545ecfb 372 r = sin( k * (c + 0.0) );
nxp_ip 21:3b75b545ecfb 373 g = sin( k * (c + 100.0) );
nxp_ip 21:3b75b545ecfb 374 b = sin( k * (c + 200.0) );
nxp_ip 21:3b75b545ecfb 375 r = (0 < r) ? r * 255.0 : 0;
nxp_ip 21:3b75b545ecfb 376 g = (0 < g) ? g * 255.0 : 0;
nxp_ip 21:3b75b545ecfb 377 b = (0 < b) ? b * 255.0 : 0;
nxp_ip 21:3b75b545ecfb 378 #else
nxp_ip 21:3b75b545ecfb 379 r = (sin( k * (c + 0.0) ) + 1) * f;
nxp_ip 21:3b75b545ecfb 380 g = (sin( k * (c + 100.0) ) + 1) * f;
nxp_ip 21:3b75b545ecfb 381 b = (sin( k * (c + 200.0) ) + 1) * f;
nxp_ip 21:3b75b545ecfb 382 #endif
nxp_ip 21:3b75b545ecfb 383 for ( int i = 0; i < N_OF_LEDS; i += N_LED_PER_BOARD ) {
nxp_ip 21:3b75b545ecfb 384 for ( int j = 0; j < 12; j += 3 ) {
nxp_ip 21:3b75b545ecfb 385 gLEDs[ i + j + 0 ] = (char)r;
nxp_ip 21:3b75b545ecfb 386 gLEDs[ i + j + 1 ] = (char)g;
nxp_ip 21:3b75b545ecfb 387 gLEDs[ i + j + 2 ] = (char)b;
nxp_ip 21:3b75b545ecfb 388 }
nxp_ip 21:3b75b545ecfb 389 for ( int j = 12; j < 15; j ++ )
nxp_ip 21:3b75b545ecfb 390 gLEDs[ i + j ] = (char)((((2500 <= count) && (count < 3000)) ? ((float)(count - 2500) / 500.0) : 0.0) * 255.0);
nxp_ip 21:3b75b545ecfb 391 }
nxp_ip 21:3b75b545ecfb 392 }
nxp_ip 21:3b75b545ecfb 393
nxp_ip 21:3b75b545ecfb 394 //void pattern_color_phase( int count ) {
nxp_ip 21:3b75b545ecfb 395 void pattern_colors( int count )
nxp_ip 21:3b75b545ecfb 396 {
nxp_ip 21:3b75b545ecfb 397
nxp_ip 21:3b75b545ecfb 398 if ( !count ) {
nxp_ip 21:3b75b545ecfb 399 gMotor_count = 0;
nxp_ip 21:3b75b545ecfb 400 setup_transfer( CH_FM_PLUS, mot_norm_op_transfer, sizeof( mot_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 401 start( CH_FM_PLUS ); // just update PCA9629 registers. no motor action
nxp_ip 21:3b75b545ecfb 402 }
nxp_ip 21:3b75b545ecfb 403
nxp_ip 21:3b75b545ecfb 404 if ( !((count + 20) & 0x3F) ) {
nxp_ip 21:3b75b545ecfb 405 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order[ gMotor_count % 5 ], 0x26, 0x80 | ((gMotor_count / 5) & 0x1) );
nxp_ip 21:3b75b545ecfb 406 gMotor_count++;
nxp_ip 21:3b75b545ecfb 407 }
nxp_ip 21:3b75b545ecfb 408
nxp_ip 21:3b75b545ecfb 409 #define PI 3.14159265358979323846
nxp_ip 21:3b75b545ecfb 410
nxp_ip 21:3b75b545ecfb 411 float p;
nxp_ip 21:3b75b545ecfb 412 float k;
nxp_ip 21:3b75b545ecfb 413 float c;
nxp_ip 21:3b75b545ecfb 414 float f;
nxp_ip 21:3b75b545ecfb 415
nxp_ip 21:3b75b545ecfb 416 k = (2 * PI) / 300.0;
nxp_ip 21:3b75b545ecfb 417 p = 300.0 / N_OF_LEDS;
nxp_ip 21:3b75b545ecfb 418 c = count;
nxp_ip 21:3b75b545ecfb 419 f = 127.5 * ((count < 500) ? c / 500.0 : 1.0);
nxp_ip 21:3b75b545ecfb 420
nxp_ip 21:3b75b545ecfb 421 for ( int i = 0; i < N_OF_LEDS; i += N_LED_PER_BOARD ) {
nxp_ip 21:3b75b545ecfb 422 for ( int j = 0; j < 12; j += 3 ) {
nxp_ip 21:3b75b545ecfb 423 gLEDs[ i + j + 0 ] = (char)((sin( k * (c + 0.0) + p * (i + j) ) + 1) * f);
nxp_ip 21:3b75b545ecfb 424 gLEDs[ i + j + 1 ] = (char)((sin( k * (c + 100.0) + p * (i + j) ) + 1) * f);
nxp_ip 21:3b75b545ecfb 425 gLEDs[ i + j + 2 ] = (char)((sin( k * (c + 200.0) + p * (i + j) ) + 1) * f);
nxp_ip 21:3b75b545ecfb 426 }
nxp_ip 21:3b75b545ecfb 427 for ( int j = 12; j < 15; j ++ )
nxp_ip 21:3b75b545ecfb 428 gLEDs[ i + j ] = (char)((((2500 <= count) && (count < 3000)) ? ((float)(count - 2500) / 500.0) : 0.0) * 255.0);
nxp_ip 21:3b75b545ecfb 429 }
nxp_ip 21:3b75b545ecfb 430 }
nxp_ip 21:3b75b545ecfb 431
nxp_ip 21:3b75b545ecfb 432
nxp_ip 21:3b75b545ecfb 433
nxp_ip 21:3b75b545ecfb 434
nxp_ip 21:3b75b545ecfb 435
nxp_ip 21:3b75b545ecfb 436 void pattern_one_by_one( int count )
nxp_ip 21:3b75b545ecfb 437 {
nxp_ip 21:3b75b545ecfb 438 if ( count == 0 ) {
nxp_ip 21:3b75b545ecfb 439 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 440 return;
nxp_ip 21:3b75b545ecfb 441 }
nxp_ip 21:3b75b545ecfb 442
nxp_ip 21:3b75b545ecfb 443 gLEDs[ (count / 9) % N_OF_LEDS ] = nine_step_intensity[ count % 9 ];
nxp_ip 21:3b75b545ecfb 444 }
nxp_ip 21:3b75b545ecfb 445
nxp_ip 21:3b75b545ecfb 446 void pattern_random( int count )
nxp_ip 21:3b75b545ecfb 447 {
nxp_ip 21:3b75b545ecfb 448 if ( count == 0 ) {
nxp_ip 21:3b75b545ecfb 449 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 450 return;
nxp_ip 21:3b75b545ecfb 451 }
nxp_ip 21:3b75b545ecfb 452 gLEDs[ rand() % N_OF_LEDS ] = rand() % 0xFF;
nxp_ip 21:3b75b545ecfb 453 }
nxp_ip 21:3b75b545ecfb 454
nxp_ip 21:3b75b545ecfb 455 void pattern_random_with_decay0( int count )
nxp_ip 21:3b75b545ecfb 456 {
nxp_ip 21:3b75b545ecfb 457 if ( count == 0 ) {
nxp_ip 21:3b75b545ecfb 458 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 459 return;
nxp_ip 21:3b75b545ecfb 460 }
nxp_ip 21:3b75b545ecfb 461 gLEDs[ rand() % N_OF_LEDS ] = 0xFF;
nxp_ip 21:3b75b545ecfb 462
nxp_ip 21:3b75b545ecfb 463 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 464 gLEDs[ i ] = (char)((float)gLEDs[ i ] * 0.90);
nxp_ip 21:3b75b545ecfb 465 }
nxp_ip 21:3b75b545ecfb 466
nxp_ip 21:3b75b545ecfb 467 void pattern_random_with_decay1( int count )
nxp_ip 21:3b75b545ecfb 468 {
nxp_ip 21:3b75b545ecfb 469 if ( count == 0 ) {
nxp_ip 21:3b75b545ecfb 470 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 471 return;
nxp_ip 21:3b75b545ecfb 472 }
nxp_ip 21:3b75b545ecfb 473 gLEDs[ rand() % N_OF_LEDS ] = 0xFF;
nxp_ip 21:3b75b545ecfb 474
nxp_ip 21:3b75b545ecfb 475 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 476 gLEDs[ i ] = (char)((float)gLEDs[ i ] * 0.7);
nxp_ip 21:3b75b545ecfb 477 }
nxp_ip 21:3b75b545ecfb 478
nxp_ip 21:3b75b545ecfb 479 void pattern_flashing( int count )
nxp_ip 21:3b75b545ecfb 480 {
nxp_ip 21:3b75b545ecfb 481 #define SUSTAIN_DURATION 10
nxp_ip 21:3b75b545ecfb 482 static float interval;
nxp_ip 21:3b75b545ecfb 483 static int timing;
nxp_ip 21:3b75b545ecfb 484 static int sustain;
nxp_ip 21:3b75b545ecfb 485
nxp_ip 21:3b75b545ecfb 486 if ( count == 0 ) {
nxp_ip 21:3b75b545ecfb 487 interval = 100.0;
nxp_ip 21:3b75b545ecfb 488 timing = 0;
nxp_ip 21:3b75b545ecfb 489 sustain = SUSTAIN_DURATION;
nxp_ip 21:3b75b545ecfb 490 vib_all_PCA9629();
nxp_ip 21:3b75b545ecfb 491 }
nxp_ip 21:3b75b545ecfb 492 if ( (timing == count) || !((int)interval) ) {
nxp_ip 21:3b75b545ecfb 493 sustain = SUSTAIN_DURATION;
nxp_ip 21:3b75b545ecfb 494 all_LEDs_turn_on();
nxp_ip 21:3b75b545ecfb 495 start_all_PCA9629();
nxp_ip 21:3b75b545ecfb 496
nxp_ip 21:3b75b545ecfb 497 timing += (int)interval;
nxp_ip 21:3b75b545ecfb 498 interval *= 0.96;
nxp_ip 21:3b75b545ecfb 499 } else {
nxp_ip 21:3b75b545ecfb 500 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 501 gLEDs[ i ] = (char)((float)gLEDs[ i ] * 0.90);
nxp_ip 21:3b75b545ecfb 502
nxp_ip 21:3b75b545ecfb 503 if ( sustain-- < 0 )
nxp_ip 21:3b75b545ecfb 504 stop_all_PCA9629();
nxp_ip 21:3b75b545ecfb 505 }
nxp_ip 21:3b75b545ecfb 506 }
nxp_ip 21:3b75b545ecfb 507
nxp_ip 21:3b75b545ecfb 508 void stop( int count )
nxp_ip 21:3b75b545ecfb 509 {
nxp_ip 21:3b75b545ecfb 510 if ( !count ) {
nxp_ip 21:3b75b545ecfb 511 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 512 stop_all_PCA9629();
nxp_ip 21:3b75b545ecfb 513 }
nxp_ip 21:3b75b545ecfb 514 }
nxp_ip 21:3b75b545ecfb 515
nxp_ip 21:3b75b545ecfb 516 void pattern_init( int count )
nxp_ip 21:3b75b545ecfb 517 {
nxp_ip 21:3b75b545ecfb 518
nxp_ip 21:3b75b545ecfb 519 if ( !count )
nxp_ip 21:3b75b545ecfb 520 align_all_PCA9629();
nxp_ip 21:3b75b545ecfb 521 }
nxp_ip 21:3b75b545ecfb 522
nxp_ip 21:3b75b545ecfb 523
nxp_ip 21:3b75b545ecfb 524 void pattern_scan( int count )
nxp_ip 21:3b75b545ecfb 525 {
nxp_ip 21:3b75b545ecfb 526 static char gMotor_count;
nxp_ip 21:3b75b545ecfb 527
nxp_ip 21:3b75b545ecfb 528 if ( !count ) {
nxp_ip 21:3b75b545ecfb 529 gMotor_count = 0;
nxp_ip 21:3b75b545ecfb 530 setup_transfer( CH_FM_PLUS, mot_norm_op_transfer, sizeof( mot_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 531 start( CH_FM_PLUS ); // just update PCA9629 registers. no motor action
nxp_ip 21:3b75b545ecfb 532 }
nxp_ip 21:3b75b545ecfb 533
nxp_ip 21:3b75b545ecfb 534 if ( !(count & 0x1F) ) {
nxp_ip 21:3b75b545ecfb 535 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order[ gMotor_count % 5 ], 0x26, 0x80 | ((gMotor_count / 5) & 0x1) );
nxp_ip 21:3b75b545ecfb 536 gMotor_count++;
nxp_ip 21:3b75b545ecfb 537 }
nxp_ip 21:3b75b545ecfb 538
nxp_ip 21:3b75b545ecfb 539 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 540 gLEDs[ (count >> 3) % N_OF_LEDS ] = 0xFF;
nxp_ip 21:3b75b545ecfb 541 }
nxp_ip 21:3b75b545ecfb 542
nxp_ip 21:3b75b545ecfb 543 void pattern_setup_half_turns( int count )
nxp_ip 21:3b75b545ecfb 544 {
nxp_ip 21:3b75b545ecfb 545
nxp_ip 21:3b75b545ecfb 546 if ( !count ) {
nxp_ip 21:3b75b545ecfb 547 align_all_PCA9629();
nxp_ip 21:3b75b545ecfb 548 gMotor_count = 0;
nxp_ip 21:3b75b545ecfb 549 } else if ( count == 50 ) {
nxp_ip 21:3b75b545ecfb 550 setup_transfer( CH_FM_PLUS, mot_half_setup_transfer, sizeof( mot_half_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 551 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 552 } else if ( count == 60 ) {
nxp_ip 21:3b75b545ecfb 553 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order[ 4 ], 0x26, 0x80 );
nxp_ip 21:3b75b545ecfb 554 } else if ( count == 75 ) {
nxp_ip 21:3b75b545ecfb 555 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order[ 3 ], 0x26, 0x80 );
nxp_ip 21:3b75b545ecfb 556 } else if ( count == 90 ) {
nxp_ip 21:3b75b545ecfb 557 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order[ 2 ], 0x26, 0x80 );
nxp_ip 21:3b75b545ecfb 558 } else if ( count == 115 ) {
nxp_ip 21:3b75b545ecfb 559 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order[ 1 ], 0x26, 0x80 );
nxp_ip 21:3b75b545ecfb 560 } else if ( count == 150 ) {
nxp_ip 21:3b75b545ecfb 561 setup_transfer( CH_FM_PLUS, mot_half_transfer, sizeof( mot_half_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 562 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 563 }
nxp_ip 21:3b75b545ecfb 564 }
nxp_ip 21:3b75b545ecfb 565
nxp_ip 21:3b75b545ecfb 566
nxp_ip 21:3b75b545ecfb 567
nxp_ip 21:3b75b545ecfb 568 void pattern_half_turns( int count )
nxp_ip 21:3b75b545ecfb 569 {
nxp_ip 21:3b75b545ecfb 570
nxp_ip 21:3b75b545ecfb 571 #ifdef INTERVAL128MS
nxp_ip 21:3b75b545ecfb 572 if ( !(count & 0x0F) ) {
nxp_ip 21:3b75b545ecfb 573 #else
nxp_ip 21:3b75b545ecfb 574 if ( !(count & 0x1F) ) {
nxp_ip 21:3b75b545ecfb 575 #endif
nxp_ip 21:3b75b545ecfb 576 if ( gMot_cntl_order_halfturn[ gMotor_count ] )
nxp_ip 21:3b75b545ecfb 577 single_byte_write_into_a_PCA9629( CH_FM_PLUS, gMot_cntl_order_halfturn[ gMotor_count ], 0x26, 0x80 | ((gMot_cntl_order_halfturn[ gMotor_count ] >> 1) & 0x1) );
nxp_ip 21:3b75b545ecfb 578 gMotor_count++;
nxp_ip 21:3b75b545ecfb 579
nxp_ip 21:3b75b545ecfb 580 gMotor_count = (gMotor_count == 10) ? 0 : gMotor_count;
nxp_ip 21:3b75b545ecfb 581 }
nxp_ip 21:3b75b545ecfb 582
nxp_ip 21:3b75b545ecfb 583
nxp_ip 21:3b75b545ecfb 584 // all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 585 // gLEDs[ (count >> 3) % N_OF_LEDS ] = 0xFF;
nxp_ip 21:3b75b545ecfb 586 }
nxp_ip 21:3b75b545ecfb 587
nxp_ip 21:3b75b545ecfb 588
nxp_ip 21:3b75b545ecfb 589
nxp_ip 21:3b75b545ecfb 590 void pattern_fadeout300( int count )
nxp_ip 21:3b75b545ecfb 591 {
nxp_ip 21:3b75b545ecfb 592
nxp_ip 21:3b75b545ecfb 593 if ( !count )
nxp_ip 21:3b75b545ecfb 594 stop_all_PCA9629();
nxp_ip 21:3b75b545ecfb 595 else if ( count == 100 )
nxp_ip 21:3b75b545ecfb 596 align_all_PCA9629();
nxp_ip 21:3b75b545ecfb 597
nxp_ip 21:3b75b545ecfb 598 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 599 gLEDs[ i ] = (char)((float)gLEDs[ i ] * 0.994469); // (0.994469 = 1/(255^(1/999))) BUT VALUE IS TRANCATED IN THE LOOP. IT DECALYS FASTER THAN FLOAT CALC.
nxp_ip 21:3b75b545ecfb 600 }
nxp_ip 21:3b75b545ecfb 601
nxp_ip 21:3b75b545ecfb 602 void pattern_speed_variations( int count )
nxp_ip 21:3b75b545ecfb 603 {
nxp_ip 21:3b75b545ecfb 604
nxp_ip 21:3b75b545ecfb 605 char data[ 4 ];
nxp_ip 21:3b75b545ecfb 606 int v;
nxp_ip 21:3b75b545ecfb 607
nxp_ip 21:3b75b545ecfb 608 if ( !count ) {
nxp_ip 21:3b75b545ecfb 609 setup_transfer( CH_FM_PLUS, mot_norm_op_transfer, sizeof( mot_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 610
nxp_ip 21:3b75b545ecfb 611 data[ 0 ] = 0x2;
nxp_ip 21:3b75b545ecfb 612 for ( int i = 0; i < 5; i++ )
nxp_ip 21:3b75b545ecfb 613 buffer_overwrite( CH_FM_PLUS, i, 20, data, 1 ); // Set half step operation
nxp_ip 21:3b75b545ecfb 614
nxp_ip 21:3b75b545ecfb 615 for ( int i = 0; i < 5; i++ ) {
nxp_ip 21:3b75b545ecfb 616 v = 833;// 400pps for halfstep
nxp_ip 21:3b75b545ecfb 617 data[ 0 ] = data[ 2 ] = v & 0xFF;
nxp_ip 21:3b75b545ecfb 618 data[ 1 ] = data[ 3 ] = (i << 5) | (v >> 8);
nxp_ip 21:3b75b545ecfb 619 buffer_overwrite( CH_FM_PLUS, i, 23, data, 4 );
nxp_ip 21:3b75b545ecfb 620 }
nxp_ip 21:3b75b545ecfb 621
nxp_ip 21:3b75b545ecfb 622 for ( int i = 0; i < 5; i++ ) {
nxp_ip 21:3b75b545ecfb 623 v = (0x1 << (5 - i));
nxp_ip 21:3b75b545ecfb 624 data[ 0 ] = data[ 2 ] = v & 0xFF;
nxp_ip 21:3b75b545ecfb 625 data[ 1 ] = data[ 3 ] = v >> 8;
nxp_ip 21:3b75b545ecfb 626 buffer_overwrite( CH_FM_PLUS, i, 31, data, 4 );
nxp_ip 21:3b75b545ecfb 627 }
nxp_ip 21:3b75b545ecfb 628
nxp_ip 21:3b75b545ecfb 629
nxp_ip 21:3b75b545ecfb 630 }
nxp_ip 21:3b75b545ecfb 631
nxp_ip 21:3b75b545ecfb 632 if ( !(count % 500) ) {
nxp_ip 21:3b75b545ecfb 633 data[ 0 ] = 0x84 | ((count / 500) & 0x1);
nxp_ip 21:3b75b545ecfb 634 for ( int i = 0; i < 5; i++ )
nxp_ip 21:3b75b545ecfb 635 buffer_overwrite( CH_FM_PLUS, i, 39, data, 1 );
nxp_ip 21:3b75b545ecfb 636 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 637 }
nxp_ip 21:3b75b545ecfb 638 }
nxp_ip 21:3b75b545ecfb 639
nxp_ip 21:3b75b545ecfb 640 void pattern_mot_ramp_variations( int count )
nxp_ip 21:3b75b545ecfb 641 {
nxp_ip 21:3b75b545ecfb 642
nxp_ip 21:3b75b545ecfb 643 char ramp_var[5][17] = {
nxp_ip 21:3b75b545ecfb 644 { 0x5D, 0x03, 0x5D, 0x03, 0x0B, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x88 },
nxp_ip 21:3b75b545ecfb 645 { 0x4B, 0x05, 0x4B, 0x05, 0x25, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x00, 0x88 },
nxp_ip 21:3b75b545ecfb 646 { 0x15, 0x06, 0x15, 0x06, 0x2D, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x88 },
nxp_ip 21:3b75b545ecfb 647 { 0x71, 0x06, 0x71, 0x06, 0x17, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x00, 0x88 },
nxp_ip 21:3b75b545ecfb 648 { 0x9C, 0x06, 0x9C, 0x06, 0x23, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x00, 0x88 },
nxp_ip 21:3b75b545ecfb 649 };
nxp_ip 21:3b75b545ecfb 650
nxp_ip 21:3b75b545ecfb 651 if ( !count ) {
nxp_ip 21:3b75b545ecfb 652 setup_transfer( CH_FM_PLUS, mot_norm_op_transfer, sizeof( mot_norm_op_transfer ) / sizeof( transaction ) );
nxp_ip 21:3b75b545ecfb 653
nxp_ip 21:3b75b545ecfb 654 for ( int i = 0; i < 5; i++ )
nxp_ip 21:3b75b545ecfb 655 buffer_overwrite( CH_FM_PLUS, i, 23, ramp_var[ i ], 17 );
nxp_ip 21:3b75b545ecfb 656
nxp_ip 21:3b75b545ecfb 657 start( CH_FM_PLUS );
nxp_ip 21:3b75b545ecfb 658 }
nxp_ip 21:3b75b545ecfb 659
nxp_ip 21:3b75b545ecfb 660 all_LEDs_turn_off();
nxp_ip 21:3b75b545ecfb 661 gLEDs[ count % N_OF_LEDS ] = 0xFF;
nxp_ip 21:3b75b545ecfb 662
nxp_ip 21:3b75b545ecfb 663 }
nxp_ip 21:3b75b545ecfb 664
nxp_ip 21:3b75b545ecfb 665 void pattern_knightrider( int count )
nxp_ip 21:3b75b545ecfb 666 {
nxp_ip 21:3b75b545ecfb 667 short led_pat[ 12 ] = { 0x7000, 0x0004, 0x0E00, 0x0002, 0x01C0, 0x0001, 0x0038, 0x0001, 0x01C0, 0x0002, 0x0E00, 0x0004 };
nxp_ip 21:3b75b545ecfb 668 short led_bits;
nxp_ip 21:3b75b545ecfb 669
nxp_ip 21:3b75b545ecfb 670 #if 0
nxp_ip 21:3b75b545ecfb 671 //if ( !(count && 0x7) )
nxp_ip 21:3b75b545ecfb 672 {
nxp_ip 21:3b75b545ecfb 673 led_bits = led_pat[ (count >> 4) % 12 ];
nxp_ip 21:3b75b545ecfb 674 for ( int i = 0; i < N_OF_LEDS; i += N_LED_PER_BOARD ) {
nxp_ip 21:3b75b545ecfb 675 for ( int j = 0; j < N_LED_PER_BOARD; j ++ ) {
nxp_ip 21:3b75b545ecfb 676 gLEDs[ i + j ] = ((led_bits << j) & 0x4000) ? 0xFF : gLEDs[ i + j ];
nxp_ip 21:3b75b545ecfb 677 }
nxp_ip 21:3b75b545ecfb 678 }
nxp_ip 21:3b75b545ecfb 679 }
nxp_ip 21:3b75b545ecfb 680 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 681 gLEDs[ i ] = (char)((float)gLEDs[ i ] * 0.90 * ((700 < count) ? (float)(1000 - count) / 300.0 : 1.0));
nxp_ip 21:3b75b545ecfb 682 #else
nxp_ip 21:3b75b545ecfb 683 //if ( !(count && 0x7) )
nxp_ip 21:3b75b545ecfb 684 {
nxp_ip 21:3b75b545ecfb 685 led_bits = led_pat[ (count >> 4) % 12 ];
nxp_ip 21:3b75b545ecfb 686 for ( int i = 0; i < N_OF_LEDS; i += N_LED_PER_BOARD ) {
nxp_ip 21:3b75b545ecfb 687 for ( int j = 0; j < N_LED_PER_BOARD; j ++ ) {
nxp_ip 21:3b75b545ecfb 688 gLEDs[ i + j ] = ((led_bits << j) & 0x4000) ? ((744 < count) ? (1000 - count) : 255) : gLEDs[ i + j ];
nxp_ip 21:3b75b545ecfb 689 // gLEDs[ i + j ] = ((led_bits << j) & 0x4000) ? 0xFF : gLEDs[ i + j ];
nxp_ip 21:3b75b545ecfb 690 }
nxp_ip 21:3b75b545ecfb 691 }
nxp_ip 21:3b75b545ecfb 692 }
nxp_ip 21:3b75b545ecfb 693 for ( int i = 0; i < N_OF_LEDS; i++ )
nxp_ip 21:3b75b545ecfb 694 gLEDs[ i ] = (char)((float)gLEDs[ i ] * 0.90);
nxp_ip 21:3b75b545ecfb 695 #endif
nxp_ip 21:3b75b545ecfb 696
nxp_ip 21:3b75b545ecfb 697 }
nxp_ip 21:3b75b545ecfb 698 pattern _gPt[] = {
nxp_ip 21:3b75b545ecfb 699 // { 256, pattern_rampup },
nxp_ip 21:3b75b545ecfb 700 { 3000, pattern_colors },
nxp_ip 21:3b75b545ecfb 701 };
nxp_ip 21:3b75b545ecfb 702 pattern gPt[] = {
nxp_ip 21:3b75b545ecfb 703 // { 256, pattern_rampup },
nxp_ip 21:3b75b545ecfb 704 { 20, stop },
nxp_ip 21:3b75b545ecfb 705 { 120, pattern_init },
nxp_ip 21:3b75b545ecfb 706 { 3000, pattern_colors },
nxp_ip 21:3b75b545ecfb 707 { 300, pattern_fadeout300 },
nxp_ip 21:3b75b545ecfb 708 { 3000, pattern_speed_variations },
nxp_ip 21:3b75b545ecfb 709 { 250, pattern_setup_half_turns },
nxp_ip 21:3b75b545ecfb 710 { 3000, pattern_half_turns },
nxp_ip 21:3b75b545ecfb 711 { 20, stop },
nxp_ip 21:3b75b545ecfb 712 { 120, pattern_init },
nxp_ip 21:3b75b545ecfb 713 { 960, pattern_rampup_and_down_w_color },
nxp_ip 21:3b75b545ecfb 714 { 960, pattern_scan },
nxp_ip 21:3b75b545ecfb 715 { 20, stop },
nxp_ip 21:3b75b545ecfb 716 { 120, pattern_init },
nxp_ip 21:3b75b545ecfb 717 { 1024, pattern_rampup_and_down },
nxp_ip 21:3b75b545ecfb 718 { 700, pattern_mot_ramp_variations },
nxp_ip 21:3b75b545ecfb 719 { 700, pattern_mot_ramp_variations },
nxp_ip 21:3b75b545ecfb 720 { 700, pattern_mot_ramp_variations },
nxp_ip 21:3b75b545ecfb 721 { 700, pattern_mot_ramp_variations },
nxp_ip 21:3b75b545ecfb 722
nxp_ip 21:3b75b545ecfb 723 { 3000, pattern_flashing },
nxp_ip 21:3b75b545ecfb 724 { 300, pattern_fadeout300 },
nxp_ip 21:3b75b545ecfb 725 { 512, pattern_random },
nxp_ip 21:3b75b545ecfb 726 { 512, pattern_random_with_decay1 },
nxp_ip 21:3b75b545ecfb 727 { 512, pattern_random_with_decay0 },
nxp_ip 21:3b75b545ecfb 728 { 9 * 120, pattern_one_by_one },
nxp_ip 21:3b75b545ecfb 729 { 1000, pattern_knightrider },
nxp_ip 21:3b75b545ecfb 730
nxp_ip 21:3b75b545ecfb 731 };
nxp_ip 21:3b75b545ecfb 732
nxp_ip 21:3b75b545ecfb 733
nxp_ip 21:3b75b545ecfb 734
nxp_ip 21:3b75b545ecfb 735 void pattern_update( int count )
nxp_ip 21:3b75b545ecfb 736 {
nxp_ip 21:3b75b545ecfb 737 static int next_pattern_change = 0;
nxp_ip 21:3b75b545ecfb 738 static int local_count = 0;
nxp_ip 21:3b75b545ecfb 739 static int pattern_index = -1;
nxp_ip 21:3b75b545ecfb 740
nxp_ip 21:3b75b545ecfb 741 if ( next_pattern_change == count ) {
nxp_ip 21:3b75b545ecfb 742 local_count = 0;
nxp_ip 21:3b75b545ecfb 743 pattern_index++;
nxp_ip 21:3b75b545ecfb 744 pattern_index = (pattern_index == (sizeof( gPt ) / sizeof( pattern )) ) ? 0 : pattern_index;
nxp_ip 21:3b75b545ecfb 745 next_pattern_change += gPt[ pattern_index ].duration;
nxp_ip 21:3b75b545ecfb 746 }
nxp_ip 21:3b75b545ecfb 747
nxp_ip 21:3b75b545ecfb 748 (*gPt[ pattern_index ].pattern_func)( local_count++ );
nxp_ip 21:3b75b545ecfb 749 }
nxp_ip 21:3b75b545ecfb 750