-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
141 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
prompt({ | ||
title: "Code Summarizer", | ||
model: "gpt-4-32k", | ||
maxTokens: 16000, | ||
description: "Given a source file in a programming language, extract the structure" | ||
}) | ||
|
||
const { file } = await fetchText("https://raw.githubusercontent.com/microsoft/devicescript/main/packages/drivers/src/driver.ts") | ||
|
||
def("FILE", file) | ||
const urls = env.links.filter(f => /^https:\/\//.test(f.filename)) | ||
const files = await Promise.all(urls.map(async url => { | ||
const res = await fetchText(url.filename) | ||
return { | ||
label: url.label, | ||
filename: url.label, | ||
content: res.text | ||
} | ||
})) | ||
def("FILE", files) | ||
def("SPEC", env.file) | ||
|
||
$`You are an expert at programming in all known languages. | ||
For each FILE 'filename.extension', generate a summarized FILE 'filename.s.extension' that ignores the internal details | ||
of the implementation and extracts enough information for an LLM to use the code elements | ||
in the source file. Generate comments as needed.` | ||
For each FILE 'filename.ts', generate the code structure in FILE 'filename.extension.pseudo' | ||
that ignores the internal detailsof the implementation and extracts enough information for an LLM | ||
to use the code elements in the source file in the context of the SPEC task. | ||
Do not generate a pseudo-file for SPEC. | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
# PCF8563 DeviceScript Driver | ||
# PCF8563 Real-Time Clock Driver | ||
|
||
This is a DeviceScript driver for the PCF8563 real-time-clock (RTC). | ||
This is a DeviceScript driver for the PCF8563 real-time clock (RTC) peripheral. | ||
|
||
## Usage | ||
|
||
```typescript | ||
import { PCF8563 } from "./pcf8563"; | ||
|
||
async function main() { | ||
const rtc = new PCF8563(); | ||
await rtc.init(); | ||
const currentTime = await rtc.readTime(); | ||
console.log("Current time:", currentTime); | ||
} | ||
const rtc = new PCF8563(0x51); | ||
await rtc.init(); | ||
|
||
main(); | ||
const currentTime = await rtc.readTime(); | ||
console.log("Current time:", currentTime); | ||
|
||
const newTime = new Date(); | ||
await rtc.writeTime(newTime); | ||
console.log("Time updated to:", newTime); | ||
``` | ||
|
||
Sources: | ||
- [datasheet](https://files.seeedstudio.com/wiki/round_display_for_xiao/RTC-PCF8563-datasheet.pdf) | ||
- [Adafruit CircuitPython](https://github.com/adafruit/Adafruit_CircuitPython_PCF8563) | ||
## Sources | ||
|
||
- [PCF8563 Datasheet](https://files.seeedstudio.com/wiki/round_display_for_xiao/RTC-PCF8563-datasheet.pdf) | ||
- [Adafruit CircuitPython PCF8563](https://github.com/adafruit/Adafruit_CircuitPython_PCF8563) | ||
- [tuupola/pcf8563](https://github.com/tuupola/pcf8563) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class I2CDriver { | ||
constructor(devAddr, options) | ||
init() | ||
initDriver() | ||
xfer(writeBuf, numRead) | ||
writeReg(regAddr, byte) | ||
readReg(regAddr) | ||
writeRegBuf(regAddr, b) | ||
readRegBuf(regAddr, size) | ||
readBuf(size) | ||
writeBuf(b) | ||
} | ||
|
||
class I2CSensorDriver extends I2CDriver { | ||
constructor(devAddr, options) | ||
read() | ||
readData() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
# DeviceScript Drivers | ||
|
||
- [src/driver.ts](https://raw.githubusercontent.com/microsoft/devicescript/main/packages/drivers/src/driver.ts) | ||
|
||
DeviceScript is a TypeScript like language to program micro-controllers. | ||
DeviceScript is a TypeScript like language to program micro-controllers. | ||
You will need to implement drivers in TypeScript using the i2c base classes. | ||
|
||
- [./driver.ts.pseudo](./driver.ts.pseudo) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,46 @@ | ||
import { I2CDriver } from "@devicescript/drivers" | ||
import { Date } from "./date" | ||
import { I2CDriver } from "./driver"; | ||
|
||
const PCF8563_I2C_ADDR = 0x51 // Default I2C address from datasheet | ||
const PCF8563_ADDR = 0x51; // Default I2C address from datasheet | ||
|
||
const REG_SECONDS = 0x02 // Register address for SECONDS from datasheet | ||
// Register addresses from datasheet | ||
const SECONDS_REG = 0x02; | ||
const MINUTES_REG = 0x03; | ||
const HOURS_REG = 0x04; | ||
|
||
export class PCF8563 extends I2CDriver { | ||
constructor(i2cAddress: number = PCF8563_I2C_ADDR) { | ||
super(i2cAddress) | ||
} | ||
|
||
protected async initDriver(): Promise<void> { | ||
// Initialization sequence to set control registers | ||
await this.writeReg(0x00, 0x00) // Control1 register: disable all alarms and interrupts | ||
await this.writeReg(0x01, 0x00) // Control2 register: disable all alarms and interrupts | ||
} | ||
|
||
async readTime(): Promise<Date> { | ||
// TODO | ||
return undefined | ||
} | ||
|
||
async writeTime(date: Date): Promise<void> { | ||
// TODO | ||
return undefined | ||
} | ||
|
||
private bcdToDecimal(bcd: number): number { | ||
return (bcd >> 4) * 10 + (bcd & 0x0f) | ||
} | ||
|
||
private decimalToBcd(decimal: number): number { | ||
return ((decimal / 10) << 4) | decimal % 10 | ||
} | ||
|
||
async stopClock(): Promise<void> { | ||
// TODO | ||
} | ||
constructor(devAddr: number = PCF8563_ADDR, options: any = {}) { | ||
super(devAddr, options); | ||
} | ||
|
||
async init() { | ||
await this.initDriver(); | ||
// TODO: generate device initialization sequence to set control registers | ||
await this.writeReg(0x00, 0x00); // Control register 1 | ||
await this.writeReg(0x01, 0x00); // Control register 2 | ||
} | ||
|
||
async readTime(): Promise<Date> { | ||
const buf = await this.readRegBuf(SECONDS_REG, 3); | ||
const seconds = this.bcdToDecimal(buf[0] & 0x7F); | ||
const minutes = this.bcdToDecimal(buf[1] & 0x7F); | ||
const hours = this.bcdToDecimal(buf[2] & 0x3F); | ||
|
||
return new Date(0, 0, 0, hours, minutes, seconds); | ||
} | ||
|
||
async writeTime(date: Date) { | ||
const seconds = this.decimalToBcd(date.getSeconds()); | ||
const minutes = this.decimalToBcd(date.getMinutes()); | ||
const hours = this.decimalToBcd(date.getHours()); | ||
|
||
await this.writeRegBuf(SECONDS_REG, Buffer.from([seconds, minutes, hours])); | ||
} | ||
|
||
private bcdToDecimal(bcd: number): number { | ||
return (bcd >> 4) * 10 + (bcd & 0x0F); | ||
} | ||
|
||
private decimalToBcd(decimal: number): number { | ||
return ((decimal / 10) << 4) | (decimal % 10); | ||
} | ||
} |