void ADS1299::updateChannelData(){ byte inByte; int byteCounter = 0; csLow(); // open SPI for(int i=0; i<3; i++){ inByte = xfer(0x00); // read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4]) stat = (stat << 8) | inByte; } for(int i = 0; i<8; i++){ for(int j=0; j<3; j++){ // read 24 bits of channel data in 8 3 byte chunks inByte = xfer(0x00); rawChannelData[byteCounter] = inByte; byteCounter++; channelData[i] = (channelData[i]<<8) | inByte; } } csHigh(); // close SPI for(int i=0; i<8; i++){ // convert 3 byte 2's compliment to 4 byte 2's compliment if(bitRead(channelData[i],23) == 1){ channelData[i] |= 0xFF000000; }else{ channelData[i] &= 0x00FFFFFF; } } }
// Read more than one register starting at _address void ADS1299::RREGS(byte _address, byte _numRegistersMinusOne) { // for(byte i = 0; i < 0x17; i++){ // regData[i] = 0; // reset the regData array // } byte opcode1 = _address + 0x20; // RREG expects 001rrrrr where rrrrr = _address csLow(); // open SPI xfer(opcode1); // opcode1 xfer(_numRegistersMinusOne); // opcode2 for(int i = 0; i <= _numRegistersMinusOne; i++){ regData[_address + i] = xfer(0x00); // add register byte to mirror array } csHigh(); // close SPI if(verbosity){ // verbosity output for(int i = 0; i<= _numRegistersMinusOne; i++){ printRegisterName(_address + i); printHex(_address + i); Serial.print(", "); printHex(regData[_address + i]); Serial.print(", "); for(int j = 0; j<8; j++){ Serial.print(bitRead(regData[_address + i], 7-j)); if(j!=7) Serial.print(", "); } Serial.println(); delay(30); } } }
static void goodfet_destroy(device_t dev_base) { struct goodfet *gc = (struct goodfet *)dev_base; struct packet pkt; xfer(gc->serial_fd, APP_JTAG430, JTAG430_RELEASECPU, 0, NULL, &pkt); xfer(gc->serial_fd, APP_JTAG430, GLOBAL_STOP, 0, NULL, &pkt); sport_close(gc->serial_fd); free(gc); }
void ADS1299::WREG(byte _address, byte _value) { // Write ONE register at _address byte opcode1 = _address + 0x40; // WREG expects 010rrrrr where rrrrr = _address csLow(); // open SPI xfer(opcode1); // Send WREG command & address xfer(0x00); // Send number of registers to read -1 xfer(_value); // Write the value to the register csHigh(); // close SPI regData[_address] = _value; // update the mirror array if(verbosity){ // verbosity output Serial.print("Register "); printHex(_address); Serial.println(" modified."); } }
int main(void) { CPU_PRESCALE(0); GBA_DDR &= ~(1<<MISO_BIT); GBA_DDR |= (1<<MOSI_BIT) | (1<<CLK_BIT); CLK_HIGH(); usb_init(); while (!usb_configured()); _delay_ms(1000); INIT_TIMER(); while (1) { if (usb_serial_available() >= 4) { uint32_t data = 0; data |= (uint32_t)usb_serial_getchar()<<24; data |= (uint32_t)usb_serial_getchar()<<16; data |= (uint32_t)usb_serial_getchar()<<8; data |= (uint32_t)usb_serial_getchar(); xfer(&data); usb_serial_putchar((data>>24) & 0xff); usb_serial_putchar((data>>16) & 0xff); usb_serial_putchar((data>>8) & 0xff); usb_serial_putchar(data & 0xff); usb_serial_flush_output(); } }
void onDraw(SkCanvas* canvas) override { SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode)); // gradient should appear over color bitmap SkAutoTUnref<SkShader> shader0(new SkComposeShader(fLinearGradientShader, fColorBitmapShader, xfer)); // gradient should appear over alpha8 bitmap colorized by the paint color SkAutoTUnref<SkShader> shader1(new SkComposeShader(fLinearGradientShader, fAlpha8BitmapShader, xfer)); SkShader* shaders[] = { shader0.get(), shader1.get() }; SkPaint paint; paint.setColor(SK_ColorYELLOW); const SkRect r = SkRect::MakeXYWH(0, 0, SkIntToScalar(squareLength), SkIntToScalar(squareLength)); for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) { SkShader* shader = shaders[y]; canvas->save(); for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) { paint.setAlpha(alpha); paint.setShader(shader); canvas->drawRect(r, paint); canvas->translate(r.width() + 5, 0); } canvas->restore(); canvas->translate(0, r.height() + 5); } }
void ADS1299::WREGS(byte _address, byte _numRegistersMinusOne) { byte opcode1 = _address + 0x40; // WREG expects 010rrrrr where rrrrr = _address csLow(); // open SPI xfer(opcode1); // Send WREG command & address xfer(_numRegistersMinusOne); // Send number of registers to read -1 for (int i=_address; i <=(_address + _numRegistersMinusOne); i++){ xfer(regData[i]); // Write to the registers } digitalWrite(CS,HIGH); // close SPI if(verbosity){ Serial.print("Registers "); printHex(_address); Serial.print(" to "); printHex(_address + _numRegistersMinusOne); Serial.println(" modified"); } }
LinearPipelineContext(const SkShader& shader, const SkShader::ContextRec& rec, SkBitmapProcInfo* info) : INHERITED(shader, rec, info) { // Save things off in case we need to build a blitter pipeline. fSrcPixmap = info->fPixmap; fAlpha = SkColorGetA(info->fPaintColor) / 255.0f; fXMode = info->fTileModeX; fYMode = info->fTileModeY; fFilterQuality = info->fFilterQuality; fMatrixTypeMask = info->fRealInvMatrix.getType(); // Need to ensure that our pipeline is created at a 16byte aligned address fShaderPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fShaderStorage); new (fShaderPipeline) SkLinearBitmapPipeline(info->fRealInvMatrix, info->fFilterQuality, info->fTileModeX, info->fTileModeY, fAlpha, info->fPixmap); // To implement the old shadeSpan entry-point, we need to efficiently convert our native // floats into SkPMColor. The SkXfermode::D32Procs do exactly that. // sk_sp<SkXfermode> xfer(SkXfermode::Make(SkXfermode::kSrc_Mode)); fXferProc = SkXfermode::GetD32Proc(xfer.get(), 0); }
/* Read a word-aligned block from any kind of memory. * returns the number of bytes read or -1 on failure */ static int read_words(device_t dev, const struct chipinfo_memory *m, address_t addr, address_t len, uint8_t *data) { struct goodfet *gc = (struct goodfet *)dev; sport_t fd = gc->serial_fd; struct packet pkt; uint8_t req[6]; if (len > MAX_MEM_BLOCK) len = MAX_MEM_BLOCK; req[0] = addr; req[1] = addr >> 8; req[2] = addr >> 16; req[3] = addr >> 24; req[4] = len; req[5] = len >> 8; if (xfer(fd, APP_JTAG430, GLOBAL_PEEK, sizeof(req), req, &pkt) < 0) { printc_err("goodfet: read %d bytes from 0x%x failed\n", len, addr); return -1; } if (pkt.len != len) { printc_err("goodfet: short memory read (got %d, " "expected %d)\n", pkt.len, len); return -1; } memcpy(data, pkt.data, pkt.len); return len; }
static void xfer_for_each_size(void (*xfer)(int len), int slen, int elen) { int i; for (i = slen; i <= elen; i *= 2) xfer(i); }
DEF_TEST(FlatData, reporter) { // Test flattening SkShader SkPoint points[2]; points[0].set(0, 0); points[1].set(SkIntToScalar(20), SkIntToScalar(20)); SkColor colors[2]; colors[0] = SK_ColorRED; colors[1] = SK_ColorBLUE; SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, colors, NULL, 2, SkShader::kRepeat_TileMode)); testCreate<SkFlattenableTraits>(reporter, *shader); // Test SkBitmap { SkBitmap bm; bm.allocN32Pixels(50, 50); SkCanvas canvas(bm); SkPaint paint; paint.setShader(shader); canvas.drawPaint(paint); testCreate<SkBitmapTraits>(reporter, bm); } // Test SkColorFilter SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateLightingFilter(SK_ColorBLUE, SK_ColorRED)); testCreate<SkFlattenableTraits>(reporter, *cf); // Test SkXfermode SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kDstOver_Mode)); testCreate<SkFlattenableTraits>(reporter, *xfer); }
void onDrawContent(SkCanvas* canvas) override { if (!canvas->getTotalMatrix().invert(&fInvMatrix)) { return; } SkPaint paint; SkScalar texWidth = fTexScale * TexWidth; SkScalar texHeight = fTexScale * TexHeight; const SkPoint texCoords[SkPatchUtils::kNumCorners] = { { fTexX - texWidth, fTexY - texHeight}, { fTexX + texWidth, fTexY - texHeight}, { fTexX + texWidth, fTexY + texHeight}, { fTexX - texWidth, fTexY + texHeight}} ; SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(SkXfermode::kSrc_Mode)); SkScalar scaleFreq = 2.0; fShader1 = SkPerlinNoiseShader2::CreateImprovedNoise(fXFreq/scaleFreq, fYFreq/scaleFreq, 4, fSeed); fShaderCompose = SkShader::CreateComposeShader(fShader0, fShader1, nullptr); paint.setShader(fShaderCompose); canvas->drawPatch(fPts, nullptr, texCoords, xfer, paint); draw_control_points(canvas, fPts); SkSafeUnref(fShader1); SkSafeUnref(fShaderCompose); }
void rdm_str_addr_sr_xfer_for_each_size(void (*xfer)(int len), int slen, int elen) { int i; for (i = slen; i <= elen; i *= 2) { xfer(i); } }
//Reads/Writes next byte. Call 'n' times to read/write 'n' number of bytes. Should be called after _beginSPI() uint8_t SPIFlash::_nextByte(char IOType, uint8_t data) { #if defined (ARDUINO_ARCH_SAMD) #ifdef ENABLEZERODMA union { uint8_t dataBuf[1]; uint8_t val; } rxData, txData; txData.val = data; spi_transfer(txData.dataBuf, rxData.dataBuf, 1); return rxData.val; #else return xfer(data); #endif #else return xfer(data); #endif }
//Reads/Writes next data buffer. Should be called after _beginSPI() void SPIFlash::_nextBuf(uint8_t opcode, uint8_t *data_buffer, uint32_t size) { uint8_t *_dataAddr = &(*data_buffer); switch (opcode) { case READDATA: #if defined (ARDUINO_ARCH_SAM) due.SPIRecByte(&(*data_buffer), size); #elif defined (ARDUINO_ARCH_SAMD) #ifdef ENABLEZERODMA spi_read(&(*data_buffer), size); #else _spi->transfer(&data_buffer[0], size); #endif #elif defined (ARDUINO_ARCH_AVR) SPI.transfer(&(*data_buffer), size); #else for (uint16_t i = 0; i < size; i++) { *_dataAddr = xfer(NULLBYTE); _dataAddr++; } #endif break; case PAGEPROG: #if defined (ARDUINO_ARCH_SAM) due.SPISendByte(&(*data_buffer), size); #elif defined (ARDUINO_ARCH_SAMD) #ifdef ENABLEZERODMA spi_write(&(*data_buffer), size); #else _spi->transfer(&data_buffer[0], size); #endif #elif defined (ARDUINO_ARCH_AVR) SPI.transfer(&(*data_buffer), size); #else for (uint16_t i = 0; i < size; i++) { xfer(*_dataAddr); _dataAddr++; } #endif break; } }
void ADS1299::RDATA() { // use in Stop Read Continuous mode when DRDY goes low byte inByte; // to read in one sample of the channels csLow(); // open SPI xfer(_RDATA); // send the RDATA command stat = xfer(0x00); // read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4]) for(int i = 0; i<8; i++){ for(int j=0; j<3; j++){ // read in the status register and new channel data inByte = xfer(0x00); channelData[i] = (channelData[i]<<8) | inByte; } } csHigh(); // close SPI for(int i=0; i<8; i++){ if(bitRead(channelData[i],23) == 1){ // convert 3 byte 2's compliment to 4 byte 2's compliment channelData[i] |= 0xFF000000; }else{ channelData[i] &= 0x00FFFFFF; } } }
static int goodfet_halt(struct goodfet *gc) { struct packet pkt; if (xfer(gc->serial_fd, APP_JTAG430, JTAG430_HALTCPU, 0, NULL, &pkt) < 0) { printc_err("goodfet: failed to release CPU\n"); return -1; } return 0; }
byte ADS1299::RREG(byte _address) { // reads ONE register at _address byte opcode1 = _address + 0x20; // RREG expects 001rrrrr where rrrrr = _address csLow(); // open SPI xfer(opcode1); // opcode1 xfer(0x00); // opcode2 regData[_address] = xfer(0x00);// update mirror location with returned byte csHigh(); // close SPI if (verbosity){ // verbosity output printRegisterName(_address); printHex(_address); Serial.print(", "); printHex(regData[_address]); Serial.print(", "); for(byte j = 0; j<8; j++){ Serial.print(bitRead(regData[_address], 7-j)); if(j!=7) Serial.print(", "); } Serial.println(); } return regData[_address]; // return requested register value }
void unmap_tags( Mesh* old_mesh, Mesh* new_mesh, Int ent_dim, LOs new_ents2old_ents) { for (Int i = 0; i < old_mesh->ntags(ent_dim); ++i) { auto tag = old_mesh->get_tag(ent_dim, i); if (is<I8>(tag)) { new_mesh->add_tag<I8>(ent_dim, tag->name(), tag->ncomps(), tag->xfer(), tag->outflags(), unmap(new_ents2old_ents, to<I8>(tag)->array(), tag->ncomps())); } else if (is<I32>(tag)) { new_mesh->add_tag<I32>(ent_dim, tag->name(), tag->ncomps(), tag->xfer(), tag->outflags(), unmap(new_ents2old_ents, to<I32>(tag)->array(), tag->ncomps())); } else if (is<I64>(tag)) { new_mesh->add_tag<I64>(ent_dim, tag->name(), tag->ncomps(), tag->xfer(), tag->outflags(), unmap(new_ents2old_ents, to<I64>(tag)->array(), tag->ncomps())); } else if (is<Real>(tag)) { new_mesh->add_tag<Real>(ent_dim, tag->name(), tag->ncomps(), tag->xfer(), tag->outflags(), unmap(new_ents2old_ents, to<Real>(tag)->array(), tag->ncomps())); } } }
static int spi_gpio_transfer(struct spi_t * spi, struct spi_msg_t * msg) { struct spi_gpio_pdata_t * pdat = (struct spi_gpio_pdata_t *)spi->priv; int (*xfer)(struct spi_gpio_pdata_t * pdat, u32_t (*txrx)(struct spi_gpio_pdata_t * pdat, u32_t val, int bits, int ns), int ns, struct spi_msg_t * msg); int ns; if(msg->bits <= 8) xfer = spi_gpio_bitbang_xfer_8; else if(msg->bits <= 16) xfer = spi_gpio_bitbang_xfer_16; else if(msg->bits <= 32) xfer = spi_gpio_bitbang_xfer_32; else return 0; if(msg->speed > 0) ns = (1000000000 / 2) / msg->speed; else ns = 10; switch(msg->mode & 0x3) { case 0: return xfer(pdat, spi_gpio_bitbang_txrx_mode0, ns, msg); case 1: return xfer(pdat, spi_gpio_bitbang_txrx_mode1, ns, msg); case 2: return xfer(pdat, spi_gpio_bitbang_txrx_mode2, ns, msg); case 3: return xfer(pdat, spi_gpio_bitbang_txrx_mode3, ns, msg); default: break; } return 0; }
void work(void){ uint32_t xdata; uint32_t cmd,data; mmio_write(FUC_NEWSCRATCH_SET2, 8); if (q2get != q2put) { struct qe *ptr = &q2[q2get & 7]; cmd = ptr->cmd & ~0x7800; data = ptr->data; if (++q2get == 0x10) q2get = 0; } else if (qget != qput) { struct qe *ptr = &queue[qget & 7]; cmd = ptr->cmd & ~0x7800; data = ptr->data; if (++qget == 0x10) qget = 0; } else { mmio_write(FUC_NEWSCRATCH_CLEAR2, 8); return; } in_temp_cmd = cmd; in_temp_data = data; set4160(); waitdone_12(); mmio_write(0xa24, 0); mmio_write(FUC_MEM_CHAN, 0); /* type=nv50_channnel????? */ mmio_write(FUC_MEM_CMD, 7); while (mmio_read(FUC_MEM_CMD)&0x1f); setxferbase(10); extr(xdata,0x08020495,28,29); // base, //xfer(0x80020494<<4,0,1,0,xdata,1,1,2); xfer(0x20495<<4,0,5,&temp[0],0,2,1,2); clear4160(); mmio_write(0x808, 0xb0000000 | temp[0]); mmio_write(0x804, 0xb0000000 | temp[1]); mmio_write(0x80c, 0x12345678); }
/* Write a word to RAM. */ static int write_ram_word(sport_t fd, address_t addr, uint16_t value) { uint8_t req[6]; struct packet pkt; req[0] = addr; req[1] = addr >> 8; req[2] = 0; req[3] = 0; req[4] = value; req[5] = value >> 8; if (xfer(fd, APP_JTAG430, GLOBAL_POKE, sizeof(req), req, &pkt) < 0) { printc_err("goodfet: failed to write word at 0x%x\n", addr); return -1; } return 0; }
static int goodfet_erase(device_t dev_base, device_erase_type_t type, address_t addr) { struct goodfet *gc = (struct goodfet *)dev_base; struct packet pkt; if (type != DEVICE_ERASE_MAIN) { printc_err("goodfet: only main memory erase is supported\n"); return -1; } if (xfer(gc->serial_fd, APP_JTAG430, JTAG430_ERASEFLASH, 0, NULL, &pkt) < 0) { printc_err("goodfet: erase failed\n"); return -1; } return 0; }
static int init_device(sport_t fd) { struct packet pkt; printc_dbg("Initializing...\n"); if (xfer(fd, APP_JTAG430, GLOBAL_NOK, 0, NULL, &pkt) < 0) { printc_err("goodfet: comms test failed\n"); return -1; } printc_dbg("Setting up JTAG pins\n"); if (xfer(fd, APP_JTAG430, GLOBAL_SETUP, 0, NULL, &pkt) < 0) { printc_err("goodfet: SETUP command failed\n"); return -1; } printc_dbg("Starting JTAG\n"); if (xfer(fd, APP_JTAG430, GLOBAL_START, 0, NULL, &pkt) < 0) { printc_err("goodfet: START command failed\n"); return -1; } if (pkt.len < 1) { printc_err("goodfet: bad response to JTAG START\n"); return -1; } printc("JTAG ID: 0x%02x\n", pkt.data[0]); if (pkt.data[0] != 0x89 && pkt.data[0] != 0x91) { printc_err("goodfet: unexpected JTAG ID: 0x%02x\n", pkt.data[0]); xfer(fd, APP_JTAG430, GLOBAL_STOP, 0, NULL, &pkt); return -1; } printc_dbg("Halting CPU\n"); if (xfer(fd, APP_JTAG430, JTAG430_HALTCPU, 0, NULL, &pkt) < 0) { printc_err("goodfet: HALTCPU command failed\n"); xfer(fd, APP_JTAG430, GLOBAL_STOP, 0, NULL, &pkt); return -1; } return 0; }
/* Write a word-aligned flash block. The starting address must be within * the flash memory range. */ static int write_flash_block(sport_t fd, address_t addr, address_t len, const uint8_t *data) { uint8_t req[MAX_MEM_BLOCK + 4]; struct packet pkt; req[0] = addr >> 0; req[1] = addr >> 8; req[2] = addr >> 16; req[3] = addr >> 24; memcpy(req + 4, data, len); if (xfer(fd, APP_JTAG430, JTAG430_WRITEFLASH, len + 4, req, &pkt) < 0) { printc_err("goodfet: failed to write " "flash block of size %d at 0x%x\n", len, addr); return -1; } return 0; }
static SkShader* make_shader(SkXfermode::Mode mode) { SkPoint pts[2]; SkColor colors[2]; pts[0].set(0, 0); pts[1].set(SkIntToScalar(100), 0); colors[0] = SK_ColorRED; colors[1] = SK_ColorBLUE; SkAutoTUnref<SkShader> shaderA(SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode)); pts[0].set(0, 0); pts[1].set(0, SkIntToScalar(100)); colors[0] = SK_ColorBLACK; colors[1] = SkColorSetARGB(0x80, 0, 0, 0); SkAutoTUnref<SkShader> shaderB(SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode)); SkAutoTUnref<SkXfermode> xfer(SkXfermode::Create(mode)); return new SkComposeShader(shaderA, shaderB, xfer); }
/* * Cu-like take command */ void cu_take(char cc) { int fd, argc; char line[BUFSIZ], *expand(), *cp; if (prompt("[take] ", copyname, sizeof(copyname))) return; if ((argc = args(copyname, argv, sizeof(argv)/sizeof(argv[0]))) < 1 || argc > 2) { printf("usage: <take> from [to]\r\n"); return; } if (argc == 1) argv[1] = argv[0]; cp = expand(argv[1]); if ((fd = creat(cp, 0666)) < 0) { printf("\r\n%s: cannot create\r\n", argv[1]); return; } (void)snprintf(line, sizeof(line), "cat %s ; echo \"\" ; echo ___tip_end_of_file_marker___", argv[0]); xfer(line, fd, "\n___tip_end_of_file_marker___\n"); }
static int goodfet_reset(struct goodfet *gc) { static const uint8_t cmd_seq[] = { JTAG430_RELEASECPU, GLOBAL_STOP, GLOBAL_START, JTAG430_HALTCPU }; int i; /* We don't have a POR request, so just restart JTAG */ for (i = 0; i < 4; i++) { struct packet pkt; if (xfer(gc->serial_fd, APP_JTAG430, cmd_seq[i], 0, NULL, &pkt) < 0) { printc_err("goodfet: reset: command 0x%02x failed\n", cmd_seq[i]); return -1; } } return 0; }
void main(int argc, char **argv) { int conn, ctlfd, fd, n; char buf[128], *base, *mtpt, *post, *url; mtpt = "/mnt/web"; post = nil; base = nil; ARGBEGIN{ default: usage(); case 'b': base = EARGF(usage()); break; case 'm': mtpt = EARGF(usage()); break; case 'p': post = EARGF(usage()); break; }ARGEND; if (argc != 1) usage(); url = argv[0]; snprint(buf, sizeof buf, "%s/clone", mtpt); if((ctlfd = open(buf, ORDWR)) < 0) sysfatal("couldn't open %s: %r", buf); if((n = read(ctlfd, buf, sizeof buf-1)) < 0) sysfatal("reading clone: %r"); if(n == 0) sysfatal("short read on clone"); buf[n] = '\0'; conn = atoi(buf); if(base) if(fprint(ctlfd, "baseurl %s", base) < 0) sysfatal("baseurl ctl write: %r"); if(fprint(ctlfd, "url %s", url) <= 0) sysfatal("get ctl write: %r"); if(post){ snprint(buf, sizeof buf, "%s/%d/postbody", mtpt, conn); if((fd = open(buf, OWRITE)) < 0) sysfatal("open %s: %r", buf); if(write(fd, post, strlen(post)) < 0) sysfatal("post write failed: %r"); close(fd); } snprint(buf, sizeof buf, "%s/%d/body", mtpt, conn); if((fd = open(buf, OREAD)) < 0) sysfatal("open %s: %r", buf); xfer(fd, 1); exits(nil); }
void ADS1299::SDATAC() { csLow(); xfer(_SDATAC); csHigh(); delayMicroseconds(3); //must wait 4 tCLK cycles after executing this command (Datasheet, pg. 37) }