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